Hey Parsifal, Well you should know that when you use a Unidirectional One-To-One, Doctrine will create a unique constraint for you on the side of where you are mapping it to the other entity. In this case Doctrine will add a unique and foreign key constraint for you on the child entity since this one is pointing to your parent. See reference - the generated MySql schema: http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html#one-to-one-unidirectional
So no you don't need to add an unique constraint within your entity as Doctrine will do this for you when creating the database schema! A PK constraint is always a unique value so you don't need to add a unique constraint since it is already a unique value or combination of values. Sorry for the confusion. One final note if your child entity doesn't contain any extra fields (if you compare it with your parent) you might consider to make a One-To-One Self-referencing association. In this case an entity can be a parent or an child, while being of the same class/type. If you could share how you did setup your entities, it would help a lot to clarify what you're trying to achieve. Op woensdag 29 juli 2015 11:47:03 UTC+2 schreef Parsifal: > > Hi, > > I was not using that uniqueCinstraint in my entity as you show the > example, the entity just had a PK (parent_id) and I used it as FK for > unidirectional oneToOne relation from this child entity to parent entity. > Then I ran update schema tool and it suggested that uniqueConstraint sql. > I applied that sql on db. > > 1) I guess running that sql was enough and I should not add that > uniqueConstraint in my entity too as it caused the error I said? Or that > uniqueConstraint should be in entity too, why did I get that error? > > 2) Does a PK really need to have a uniqueConstraint? > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
