Symfony2 Doctrine2 trouble with optional one to one relation

后端 未结 5 1567
小蘑菇
小蘑菇 2021-01-01 12:53

I have a problem with Doctrine2 in Symfony2 and two relationed entities.

There is a user-entity that can (not must) have a usermeta-entity referenced which

5条回答
  •  梦谈多话
    2021-01-01 13:09

    You're using the wrong type of Relation for your problem.

    What you want is a unidirectional one to one from Usermeta to User.

    A bidirectional one to one relationship would mean the following:

    1. A user MUST have a Usermeta object.
    2. A Usermeta object MUST have a User.

    In your case you're only trying to require the second condition.

    This does mean that you can only hydrate User from Usermeta and not the other way around.

    Unfortunately doctrine does not support Zero or One to Many relationships.

提交回复
热议问题