I am using symfony Symfony 5.2. I have an Embeddable entity called Address, that contains fields like street, house and so on.
/**
* @ORM\Embeddable()
*/
class Address {
/**
* @ORM\Column(type="string", nullable=true, name="street", length=Constants::MAX_STREET_NAME_LENGTH)
*/
private string $street;
/**
* @ORM\Column(type="integer", nullable=true, name="house")
*/
private int $house;
/**
* @ORM\Column(type="integer", nullable=true, name="flat")
*/
private int $flat;
//More fields
There are two more entities that use this embeddable, User and Order. User:
class User implements UserInterface {
//Some code here
/**
* @Assert\Valid
* @ORM\Embedded (class="\App\Entity\Embeddable\Address", columnPrefix="user_")
*/
private Address $address;
Order:
class Order {
//Some more fields
/**
* @Assert\Valid
* @ORM\Embedded (class="\App\Entity\Embeddable\Address", columnPrefix="order_")
*/
private Address $address;
}
Here is the main problem. I want to override the column annotations for user to allow null values in address fields, such as street, and for order to not allow it. I know there is an annotation called @AttributeOverride but for some reason it is not working, I can't generate the migration or validate the database schema. The error I get is:
Invalid field override named 'address.street' for class 'App\Entity\Order'
Annotation I use for Order:
@AttributeOverrides({
@AttributeOverride(name="address.street", column=@ORM\Column (type="string",
length=Constants::MAX_STREET_NAME_LENGTH, nullable=false))
})
So the question is: is there a way to use annotations attribute overriding for embedded entities?