Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
doctrinebot opened this issue Jul 1, 2013 · 4 comments
Closed

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

doctrinebot opened this issue Jul 1, 2013 · 4 comments
Assignees

Comments

@doctrinebot
Copy link

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');
$qb->addSelect('i')
    ->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).

@doctrinebot
Copy link
Author

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 :-)

@doctrinebot
Copy link
Author

Comment created by hosiplan:

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

@doctrinebot
Copy link
Author

Comment created by hosiplan:

DDC-1149

@doctrinebot
Copy link
Author

Issue was closed with resolution "Duplicate"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants