Eager loading of references doesn't work

16 views
Skip to first unread message

Bar Ziony

unread,
Mar 10, 2013, 6:00:30 AM3/10/13
to mandang...@googlegroups.com
Hey,

I have this simple schema:
Model\Effect has a referencesMany of Model\Category ('categories' keyword in the config Classes).

$effects = $mandango->getRepository('Model\Effect')->createQuery()->references(array('categories'));
   
foreach ($effects as $effect) {
    foreach ($effect->getCategories()->createQuery() as $category) {
        echo $category->getName();
    }
}

I have a logger, and what I get is:
a find() query for effects collection (only the _id).
a find() query for categories collection, (only the _id), $in of all the unique category ids...

so far so good.

Now for each category I get: find() $in category_id, get only the 'name' field.
Also if multiple effects have the same category, Mandango just keeps querying the DB for that category, even though it already got that data from a previous effect.

The most disturbing thing is that the eager loading doesn't even work, it does the $in query for all the categories but it doesn't use it at all.

What am I doing wrong?

Thanks,
Bar.

Pablo Díez

unread,
Mar 10, 2013, 8:38:12 AM3/10/13
to mandang...@googlegroups.com
This is because of the cache. Does it happen after the cache is generated?
 

Thanks,
Bar.

--
You received this message because you are subscribed to the Google Groups "Mandango Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mandango-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bar Ziony

unread,
Mar 10, 2013, 10:25:24 AM3/10/13
to mandang...@googlegroups.com
Hi Pablo,

I'm trying multiple times (refreshing the page) - and yes, it does happen every time. And I do see the cache php file in the cache directory.

Any idea?

Thanks,
Bar.



--
You received this message because you are subscribed to a topic in the Google Groups "Mandango Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mandango-users/z5CGvmD2aLA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mandango-user...@googlegroups.com.

Pablo Díez

unread,
Mar 10, 2013, 2:51:21 PM3/10/13
to mandang...@googlegroups.com
Could you put the code somewhere to reproduce it?

Bar Ziony

unread,
Mar 10, 2013, 3:06:47 PM3/10/13
to mandang...@googlegroups.com
I found the reason:

$effects = $mandango->getRepository('Model\Effect')->createQuery()->references(array('categories'))->all();

foreach ($effects as $effect) {
    foreach ($effect->getCategories() as $category) {
        echo $category->getName();
    }
}


without all() in the first line, it works as it should (2 queries). with all() - it does those 2 queries and another findOne for each $category->getName(). 
Why all() breaks the wanted behavior?

Thanks,
Bar.


Bar Ziony

unread,
Mar 10, 2013, 3:16:29 PM3/10/13
to mandang...@googlegroups.com
Actually it doesn't work even without the all().

I don't know - the behavior is really erratic. Any idea what can cause that ? :\

Pablo Díez

unread,
Mar 13, 2013, 8:49:00 AM3/13/13
to mandang...@googlegroups.com
I've just made a test and this doesn't happen to me. Could you create a reproducible example?
Reply all
Reply to author
Forward
0 new messages