This project is archived and is in readonly mode.

#3662 ✓stale
Josh Symonds

Exclude Fields from Eager Loaded Models

Reported by Josh Symonds | January 5th, 2010 @ 08:00 PM

I have an organization that has many mailboxes, each including some amount of email. I wanted to eagerly load this association like so:

@organization.mailboxes.find(:all, :include => :emails)

Mailboxes have lots of emails, which is fine. But those emails have some very big columns (like body), which I don't necessarily always want. Loading them into Rails slows down this query quite a lot, and unfortunately I have no way to specify that I don't want to load the body in this include. So I made a patch to allow this kind of syntax:

@organization.mailboxes.find(:all, :include => {:emails => {:except => :body}})

A select statement will automatically be generated to exclude the offending column. It also accepts an array of columns:

@organization.mailboxes.find(:all, :include => {:emails => {:except => [:body, :huge_column]}})

Both body and huge_column will be excluded from the select statement.

The patch also responds correctly to through associations and nesting:

@organization.mailboxes.find(:all, :include => {:emails => {:comments => {:except => :body}}})

I've included tests with the patch, and I'm eager for feedback if people think this would be a good addition to ActiveRecord.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar October 8th, 2010 @ 12:36 PM

    • State changed from “new” to “stale”
    • Importance changed from “” to “Low”

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

  • AlexParamonov
  • Rohit Arondekar

    Rohit Arondekar February 3rd, 2011 @ 01:12 AM

    • State changed from “stale” to “open”
    • Assigned user set to “Santiago Pastorino”

    Santiago: Could you please take a look at this ticket? I'm assigning to you since you've worked on AR and AMo a lot. :)

  • rails

    rails May 4th, 2011 @ 01:00 AM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails May 4th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages