mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Question: how to map two entities who's IDs are also columns #5392
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @yogi5642 on GitHub (Jan 24, 2017).
I was trying to use Doctrine to add a layer of sense on a legacy database, and the table structure I'm having trouble with looks like this:
members
attendee
An attendee can but may not always be a member.
So with a Mapping something like:
I'm in trouble because I can't create a Member like so:
As the Member mapping using the phone_number, so when Doctrine tries to manage this relationship, seeing that it's persisting a Member with no Attendee, maps the Atendee join coulumn (the phone_number) to null, instead of what was provided.
It's https://github.com/doctrine/doctrine2/blob/v2.5.6/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L669 where the joined entity id is overwriting the specicied id, but I guess this is correct functionality.
Any suggestions on how to map this better to overcome this? I can't change this database.
@Ocramius commented on GitHub (Jan 24, 2017):
We don't support mapping a field to both an association and a scalar value: it has to be one of the two.
I think the devil is in the details here. Your sentence is a bit ambiguous:
This is unclear to me: are you maybe describing an ISA association? Maybe this should be a joined table inheritance?
@yogi5642 commented on GitHub (Jan 25, 2017):
Thanks for taking the time to comment on this, much appreciated :)
It's this
That I suspected, but couldn't find explicitly mentioned in the docs. Perhaps Doctrine could error when defining an entity like this if it is truly unsupported?
As far as I can tell, using joined table inheritance would still render me unable to make use of the scalar value if that field is also used for the join. Also, in this example an
Attendeemay exist, who does not inherit from aMember, so it doesn't seem like joined table inheritance at would work here.The only solution I can think of would be to join the entities outside of Doctrine's automatic associations.
Thanks!
@Ocramius commented on GitHub (Jan 25, 2017):
It's something we're working on for 3.x