How to retrieve an entity with all of its associations using EntityManager in Doctrine2?

前端 未结 4 528
夕颜
夕颜 2020-12-30 14:52

I have a simple entity with many-to-many and one-to-many associations. I\'m aware of \'Joins\' for fetching related associations which is a manual solution for my problem.

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 15:37

    You can use a DQL query:

    $query = $em->createQuery("SELECT p, f FROM Entities\\Patientprofile p JOIN p.Foo f WHERE p.id = ?1");
    $query->setParameter(1, 321);
    $patient = $query->getSingleResult();
    

提交回复
热议问题