Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0-ALPHA3
-
Fix Version/s: 2.1
-
Component/s: None
-
Security Level: All
-
Labels:None
Description
Sometimes, a @ManyToOne field has to be the Primary Key, or part of the Primary Key. Adding @Id to the @ManyToOne does not help, an additional property with duplicates the referenced id is needed:
(userId and User field in the Phonenumber class - to be able to set @Id on userId):
http://pastebin.com/d51e021e2
Allowing @Id on @ManyToOne fields (which would make the JoinColumn a PK) would help here. Any maybe this would also fix DDC-116
Issue Links
- is duplicated by
-
DDC-795
Wrong SQL statement when using loadOneToManyCollection
-
Thanks for your reply on doctrine-user!
My previous workaround was something like this:
http://pastie.org/private/uoawwvf75onnvph8bj1fwg
Instead of just having a $User property in the Phonenumber entity (which is mapped by the userId field in the phonenumber table), I have an additional $userId property, which is also mapped to the userId DB field. This way I could make $userId @Id (and thus add it to the PKs), but I had to manually update it when I set the $User (see the TODO annotations in the Pastie code).
I see "EntityManager#find(...)" would have to be able to also get objects as identifiers, e.g. (int, User), which may have major implications...
However I think to support constructions like this is very important as it's a very common pattern, especially for OneToOne associations with no additional identifier field (PK = FK)...