DDC-2536: AbstractQuery::setFetchMode not working as expected #3260

doctrinebot opened this Issue Jul 1, 2013 · 4 comments

2 participants


Jira issue originally created by user hosiplan:

Let's have theese entities

class Order
{ // $id, ...
    /*** @ORM\OneToMany(targetEntity="OrderItem", mappedBy="order") **/
    protected $items;

class OrderItem
{ // $id, ...
    /*** @ORM\ManyToOne(targetEntity="Order", inversedBy="items") **/
    protected $order;

    /*** @ORM\OneToMany(targetEntity="OrderItemAddition", mappedBy="orderItem") **/
    protected $additions;

class OrderItemAddition
    /*** @ORM\Id() @ORM\ManyToOne(targetEntity="OrderItem", inversedBy="additions", fetch="LAZY") **/
    protected $orderItem;

    /*** @ORM\Id() @ORM\ManyToOne(targetEntity="Addition", inversedBy="orderItems", fetch="EAGER") **/
    protected $addition;

class Addition
{ // $id, $name, ...

Now let's have a query

$qb = $repository->createQueryBuilder('o');
    ->innerJoin('o.items', 'i')
    ->orderBy('o.id', 'DESC');

$q = $qb->getQuery();
$q->setFetchMode('Damejidlo\Orders\OrderItem', 'additions', ClassMetadata::FETCH_EAGER);
$q->setFetchMode('Damejidlo\Orders\OrderItemAddition', 'addition', ClassMetadata::FETCH_EAGER);
$q->setFetchMode('Damejidlo\Orders\Order', 'corporateMember', ClassMetadata::FETCH_EAGER);

The query is ok, data is ok, BUT. This generates an awful amount of queries. I would expect 5 at most (1 count, 1 data fetch, 3 for eagers).

And no, I don't want to join more table in one query, because that's awfully unefective and makes me transfer too much data repeatedly (order every orderItem and again for every addition).

It seems to be working partially. It fetches all OrderItemAddition in one query, but not those joined to them (Addition entity).

I believe this should generate one query for every entity type as I specified, not one for each row.

I also believe, you've already had talk with author of NotORM (now you probably know exactly where this is heading).


Comment created by @beberlei:

eager fetching across entities is not yet implemented for collections. Its still deep in my mind somewhere that this needs to be done :-)


Comment created by hosiplan:

Ofcourse I found it right after I wrote this one :)


Comment created by hosiplan:



Issue was closed with resolution "Duplicate"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment