0 votes

So far each time I create an association, one of the field is "locked" to the target entity PK.
I want to create associations with another field, which is likely unique, but which isn't the primary key of the entity.

closed with the note: Solved
in General Questions by (190 points)
closed by

2 Answers

0 votes
Best answer

As far as I know, Doctrine2 doesn't support association to non-pk field. This is also the reason why Skipper automatically creates association to primary fields only in Doctrine2.

by Skipper developer (138k points)
selected by

I just came across this page:
(CTRL+F "Many to One using non-PK foreign key")

Which show a sample YML (and the guy is using Skipper, that's why I found this site in the first place)

Yes, but you're referring to Doctrine1 documentation and tagged your question as Doctrine2. So it depends which ORM you're using ;-).

In case you're using Doctrine1, simply double-click on inverse field and choose appropriated field from combo box:

Skipper Doctrine association editor

But if you're using Doctrine2, then there isn't this option because Doctrine2 doesn't support it (and if you will check ormcheatsheet.com, you will see that for Doctrine2 there is no such example).

0 votes

Roger that, thank you very much. I'm disapointed at Doctrine2 then! :/
I need to check that further, I though I used the same feature in Doctrine2, but that may come from one of my Doctrine1 project then.

by (190 points)

You're welcome. Unfortunately Doctrine2 misses a lot of features which original Doctrine has (for example behaviors). On the other side, Doctrine2 is completely magic-free and unambiguous thanks for this.

Also the difference is in used ORM pattern, because Doctrine1 implements ActiveRecord pattern and Doctrine2 uses UnitOfWork pattern.