Symfony: Why is isInitialized always false?

I used the doctrine to query the user:

$customer = $this->getDoctrine()->getRepository('DemoUserBundle:Customer')->find(1);

But I got the result:

Client {# 1441 ▼ + isInitialized : false -id: 1 -username: null -nickname: null -email: null -salt: null -password: null -roles: null -enabled: null -lastLogin: null -expired: null - expiredAt: null -created: null -modified: null -group: null -ceilphoneCode: null -avatar: null -tasks: null -application: null-companies: null -creators: null -images: null -company: null -store: Store {# 1440 ▶} -realName: null -sex: null -age: null -belongCompany: null -address: null -server: null -relationProducts: null -attributes: null -medias: null -logs: null ... 2 }

the result is not complete, where is the other data of this user? why isInitialized is false?

+4
source share
2 answers

isInitializedfalse because you are getting an object Proxyfrom EntityManager. You probably loaded the object with Customerwith id 1as an association somewhere earlier in your application. This linked object was not connected (not loaded), and as a result, the same one is Proxynow returned from yours EntityManager. Usually findshould return a fully loaded object.

Read also this GitHub post discussing a similar issue.

+1
source

fetch="EAGER" , , .

$customer = $this->getDoctrine()->getRepository('DemoUserBundle:Customer')->find(1);

$customer = $this->getDoctrine()->getRepository('DemoUserBundle:Customer')->find(2);

.

+1

Source: https://habr.com/ru/post/1664243/


All Articles