safrazik / breeze.server.php

Breeze JS support for PHP applications
MIT License
29 stars 11 forks source link

isPartOfKey not being set correcting for keys in Embeddable properties #23

Open jasonlfunk opened 8 years ago

jasonlfunk commented 8 years ago

I have my keys stored in a UUID value object. When this is generating the metadata, the isPartOfKey flag is not being properly set for the classes.

Example:

/**
 * @Entity
 * @HasLifecycleCallbacks()
 **/
class Expense extends Base
{
    /**
     * @Embedded(class="Objects\UUID", columnPrefix=false)
     * @var UUID
     **/
    protected $id;
   ....
}
/**
 * @Embeddable
 */
class UUID
{
    /**
     * @Id
     * @Column(type="string")
     */
    private $id;

   ...
}

The generated Metadata looks like this:

{
"metadataVersion":"1.0.5",
"structuralTypes":[{
   "shortName":"Expense",
   "autoGeneratedKeyType":"None",
   "defaultResourceName":"Expenses",
   "dataProperties":[
      {"name":"id","dataType":"String"}
      ...
   ]
}

It appears that Embeddables aren't being evaluated correctly.

safrazik commented 8 years ago

Embeddables is a Doctrine 2.5 feature. Yes it's not supported by the library yet. I'll have a look at the issue. Please feel free to contribute!

safrazik commented 8 years ago

ok! Embeddables are the breeze equivalent of Complex Types. Relating to your issue: The Doctrine documentation says embeddables don’t have a primary key which makes sense as they are not entities, but your UUID embeddable has a primary key like an entity. I think it is wrong. Second, your Expense entity has a primary key which is type of an embeddable. I wonder if Doctrine library supports Embeddable to be a primary key of en entity type.

jasonlfunk commented 8 years ago

Hi - thanks for responding.

1) You are right that an embeddable doesn't have a primary key because they aren't entities. However, they can provide the primary key for another entity. This setup is currently working fine with my application.

2) Expense doesn't have a primary key directly (there is no @Id mapping on it). It get's inherited from the UUID embeddable.

Here are the relevant parts of the generated mapping:

+-------------------------------+--------------------------------------------+
| Field                         | Value                                      |
+-------------------------------+--------------------------------------------+
| Name                          | Expense                                    |
| Root entity name              |Expense                                     |
| Custom generator definition   | None                                       |
| Custom repository class       | None                                       |
| Mapped super class?           | False                                      |
| Embedded class?               | False                                      |
| Parent classes                | Empty                                      |
| Sub classes                   | Empty                                      |
| Embedded classes              | Empty                                      |
| Identifier                    | ["id.id"]                                  |
| Inheritance type              | 1                                          |
| Discriminator column          | None                                       |
| Discriminator value           | None                                       |
| Discriminator map             | Empty                                      |
| Generator type                | 5                                          |
| Table                         | {"name":"Expense"}                         |
| Composite identifier?         | False                                      |
| Foreign identifier?           | False                                      |
| Sequence generator definition | None                                       |
| Table generator definition    | None                                       |
| Association mappings:         |                                            |
|   id.id                       |                                            |
|     fieldName                 | id.id                                      |
|     type                      | string                                     |
|     length                    | Null                                       | 
|     unique                    | False                                      |
|     nullable                  | False                                      |
|     id                        | True                                       |
|     columnName                | id                                         |
|     originalClass             | UUID                                       |
|     declaredField             | id                                         |
|     originalField             | id                                         |
+-------------------------------+--------------------------------------------+

+-------------------------------+---------------------------+
| Field                         | Value                     |
+-------------------------------+---------------------------+
| Name                          | UUID                      |
| Root entity name              | UUID                      |
| Custom generator definition   | None                      |
| Custom repository class       | None                      |
| Mapped super class?           | False                     |
| Embedded class?               | True                      |
| Parent classes                | Empty                     |
| Sub classes                   | Empty                     |
| Embedded classes              | Empty                     |
| Named queries                 | Empty                     |
| Named native queries          | Empty                     |
| SQL result set mappings       | Empty                     |
| Identifier                    | ["id"]                    |
| Inheritance type              | 1                         |
| Discriminator column          | None                      |
| Discriminator value           | None                      |
| Discriminator map             | Empty                     |
| Generator type                | 5                         |
| Table                         | {"name":"UUID"}           |
| Composite identifier?         | False                     |
| Foreign identifier?           | False                     |
| Sequence generator definition | None                      |
| Table generator definition    | None                      |
| Change tracking policy        | 1                         |
| Versioned?                    | None                      |
| Version field                 | None                      |
| Read only?                    | False                     |
| Entity listeners              | Empty                     |
| Association mappings:         |                           |
| Field mappings:               |                           |
|   id                          |                           |
|     fieldName                 | id                        |
|     type                      | string                    |
|     scale                     | Empty                     |
|     length                    | Null                      |
|     unique                    | False                     |
|     nullable                  | False                     |
|     precision                 | Empty                     |
|     id                        | True                      |
|     columnName                | id                        |
+-------------------------------+---------------------------+

I was hoping something would just ring a bell and there would be an easy fix. I don't have too much experience with Reflection and what-not. But I'll definitely dig into it a little more too.