I have problem with doctrine embeddables and using associations in it. When i add @ManyToOne
to embedded entity doctrine don't create address_city
column in user table, however address_street
column is created. I seams bit strange because there is no error, city is silently ommited.
Code look like this:
/** @Entity */
class User
{
/** @Embedded(class = "Address") */
private $address;
}
/** @Embeddable */
class Address
{
/** @Column(type = "string") */
private $street;
/** @ManyToOne(targetEntity = "City") */
private $city;
}
/** @Entity */
class City
{
/** @Column(type = "string") */
private $name;
}
In this tutorial, we will learn how to embed one entity inside another entity, so they are mapped to a single table. With JPA and Hibernate we can use the @Embeddable annotation to mark a class to be eligible as an embeddable class. We can use the @Embedded annotation to embed an embeddable class.
One entity can be embedded in another entity. The attributes of an entity can be common attributes of more than one entity. In this case there can be one embeddable entity.
The attributes of an embedded class can be overridden using the @AttributeOverrides and the @AttributeOverride annotations. @Embeddable annotation - JPA provides the @Embeddable annotation to declare that a class will be embedded by other entities. @Embedded annotation - The JPA annotation @Embedded is used to embed a type into another entity.
The associative entity is always the child side of the relationships. These relationships show how two or more fundamental entities relate. The business terms, usually primary terms, that are the origin of the definition of this associative entity. A business term can be the source of one or more associative entities depending on its definition.
State for 2015.01.11:
This case is currently not supported in doctrine. It's now described in doctrine issue tracker here
Here is the explanation:
We don't support associations from embeddables right now...
It will probably not implemented for now, as embeddables (in our vision) are fitting the use-case of ValueObjects. ValueObjects are (usually) supposed to be containing serializable data, and an entity reference is not serializable data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With