Getting a “true” object from a proxy object in doctrine2

前端 未结 11 1461
南笙
南笙 2021-02-01 13:50

Doctrine uses proxy objects to represent related objects in order to facilitate lazy loading. This is a really cool feature, but its causing an issue with something I am trying

11条回答
  •  [愿得一人]
    2021-02-01 14:49

    This is unlikely to help in the specific instance for the question, since you're relying on a third-party module, but you can prevent the lazy loading by setting the "fetch mode" for your entity to "EAGER".

    User:
        ManyToOne:
            city:
                fetch: EAGER
    

    This can also be handled by annotations:

    @ManyToOne(targetEntity="city", fetch="EAGER")
    @JoinColumn(name="city", referencedColumnName="id")
    

    See http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-manytoone

    None of the other answers I've seen here worked for me.

提交回复
热议问题