Doctrine2 eager loading runs multiple queries instead of 1

后端 未结 1 1993
旧巷少年郎
旧巷少年郎 2021-01-13 06:02

I\'m using Symfony2 with Doctrine2 (latest versions) and have this relation defined:

/**
 * @ORM\\OneToMany(targetEntity=\"Field\", mappedBy=\"event\", fetch         


        
相关标签:
1条回答
  • 2021-01-13 06:46

    I believe the reason this is occurring is because you're fetching entities, not a specific query. The idea of Doctrine is that you're fetching objects, not interacting with a database but an object resource as if they're all associated/referenced like stored entities. If you need a query like you're describing you would be better off using DQL but at that point you're not fetching entities created, you're getting a custom result.

    I hope this made sense.

    Basically the default association you're using is fetching associated objects not a joined query.

    0 讨论(0)
提交回复
热议问题