lazy loading with doctrine one to one mapping

前端 未结 3 2075
一向
一向 2021-02-12 20:39

I am having a hard time finding the correct result for this.

I have one to one mapping. There are two tables:

/**
* @ORM\\Table(name=\"users\")
* @ORM\\E         


        
3条回答
  •  野的像风
    2021-02-12 21:29

    Inverse sides of one-to-one associations can not be lazy.

    Explanation:

    This is expected behavior. There is no foreign key on the inverse side, hence it is impossible to decide whether to proxy it or not. We must query for the associated object or join it. Note that this only affects inverse sides of single-valued associations, that is, really only the inverse side of bidirectional one-to-one associations.

    Why we cannot create proxy without FK?

    It is pretty simple, in a one-to-many association where the one-side is the inverse side, it holds a collection. The collection may be empty or not but there can always be a collection so it easy and correct to always put a proxy collection there.

    If you have a single-valued side that is the inverse side, how can you decide whether to put a proxy object there or not? Without seeing the foreign key you have no way to distinguish between: There is no associated object (and thus putting a proxy object in place would by simply wrong) or there is one and of which type it is, if inheritance is involved (since putting a proxy of the wrong type in is also wrong).

    See discusion on https://github.com/doctrine/orm/issues/4389

提交回复
热议问题