Is there a way to achieve the polymorphic relationship that Laravel have on doctrine?
Here is an example:
class Address
{
protected $street;
...
public function setStreet()
{
}
public function getStreet()
{
}
}
class Event
{
/*one to many*/
protected $addresses;
...
}
class Museum
{
/*one to many*/
protected $addresses;
...
}
And on the database it would be something like this:
Address:
id | type (event or museum) | type_id | street ...
Event:
id | name ...
Museum:
id | name ...
I looked at single table inheritance and it seems to solve my problem, but I did not understood how to associate the event or museum to the address. If someone could ELI5 I would be very grateful.
It does look like a use case for inheritance mapping, unless you have a ton of different entities you want to store addresses for. Using your example in Doctrine, you'd create two classes for each of your addresses.
Read more about inheritance mapping.