#298 ✓not-applicable
Corrin Meyer

Eager loading not working using ":includes" option

Reported by Corrin Meyer | May 21st, 2008 @ 09:29 AM

I have a Blogging like system were I have a Article and Comments model and the Article has many Comments. Example code is at http://pastie.caboo.se/200642.

When I try to load a single Article and eager load the articles body, the comments associated with the article and the text bodies of the comments, it seems that multiple SQL statements are issued. I am using the following command.

Article.first(:includes => [Article.body, Article.comments, Article.comments.body])

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) May 21st, 2008 @ 01:59 PM

    afaik the :include option isn't being used by dm-core yet.

  • Corrin Meyer

    Corrin Meyer May 21st, 2008 @ 02:06 PM

    Is this still planned for the 0.9.0 release?

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) May 26th, 2008 @ 04:52 PM

    No, this will not be in before the 0.9 release.

    I also want to note that I don't think we should implement :include using the same approach (old) AR uses. In their approach they pull back a huge set of data with a monolithic query joining everything together, essentially the cartesian product of whatever tables are involved. This then has to be sifted through and a comparably small number of objects are generated.

    Recently AR changed so that one query would be issued for the primary results, and then one query for each :include option. While this does mean more queries to the backend, it usually results in better performance since the total time to execute the multiple queries is often far less than the monolithic one.

  • Corrin Meyer

    Corrin Meyer May 26th, 2008 @ 08:22 PM

    Yeah, I can see that being a problem. I have played around ActiveRecord and remember when trying to include things with join tables it needing to do what you are talking about.

    I'm more concerned about modifying lazy loaded fields. In the case of a text field, it is not loaded by default. Will there be a way to tell a search to also load these lazy fields?

    For example...

    a = Article.first(:includes => [Article.body]) where "body" is a text field.

  • Corrin Meyer

    Corrin Meyer May 26th, 2008 @ 08:29 PM

    Actually, after a little more consideration, I suppose this isn't such a big deal since DM also tries to load thing intelligently trying to solve the "n+1 select" problem.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 2nd, 2008 @ 03:49 AM

    • State changed from “new” to “open”
    • Assigned user cleared.

    I can confirm this is still an issue. It may be something that in planning for the DM 1.0 roadmap.

    I still have my reservations, and am concerned about how we're going to do it in an adapter agnostic way, but I guess we'll see how it goes.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 4th, 2008 @ 03:24 AM

    • State changed from “open” to “not-applicable”

    I am going to mark this as not-applicable, mainly because it's not really a bug since it's not a feature that is supported yet.

    Also, we're trying to avoid using LH as a TODO list and using it only to manage bugs and patches, and given that this is a clear item on the roadmap I am going to remove this from Lighthouse.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket