I am trying to store a number of address entities within a single customer entity.
That part is easy, as its just a simple ManyToOne/OneToMany bidirectional relationship.
Take a look at our simple code, but notice the question I am posing with the additional OneToOne association I am trying to make on Customer for primary_address
class Address
{
/**
* @ORM\Column
*/
protected $address_text;
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="addresses")
*/
protected $customer;
}
class Customer
{
/**
* @ORM\OneToMany(targetEntity="Address", mappedBy="customer")
*/
protected $addresses;
/**
* @ORM\OneToOne(targetEntity="Address")
*/
protected $primary_address;
}
So, each Customer entity should be able to have a number of Address entities associated with it, but the Customer entity should also have just one of them be a Primary Address.
How is this possible? Are there any elegant solutions?