This project is archived and is in readonly mode.

#1060 ✓wontfix
Frederick Cheung

Allow :select option with join-based include

Reported by Frederick Cheung | September 16th, 2008 @ 06:42 PM

This patch adds the ability to use custom select clauses with a join base :include. It does not support completely overwriting the select (since :include relies on having everything where it expects it) but allows one to select extra columns (eg piggy backed attributes).

Comments and changes to this ticket

  • Rob Anderton

    Rob Anderton September 19th, 2008 @ 06:04 PM


    This is very handy: something I've needed quite a few times.

  • Chris Heald

    Chris Heald October 7th, 2008 @ 01:10 AM


    Definitely needed. The current model precludes the access of join model data while eager loading - definitely not an optimal situation.

    To illustrate the problem:


    tag => id, name tagging => id, tag_id, taggable_id, taggable_type, context

    has_many :through definition

    has_many :people, :class_name => "Tag", :through => :people_taggings, :source => :tag, :select => "tags.*, taggings.context"

    No eager loading, success

    n = Node.first => #<Nodes::Book id: 1, ...> n.people.last.context => "author"

    Eager loading, fails when getting join model data

    n = Node.first :include => [:people] => #<Nodes::Book id: 1, ...> n.people.last.context NoMethodError: undefined method context' for #<Tag id: 16953, name: "Some Author">

  • Pratik

    Pratik October 7th, 2008 @ 01:56 PM

    • Milestone cleared.

    Let's tackle this post 2.2

  • John

    John December 5th, 2008 @ 11:12 AM

    the extra :select columns are being added after the join columns, we're using :select to specify SQL_CALC_FOUND_ROWS, which needs to be the first clause in the select, could the :select columns be preprended rather than appended to the list?

  • Espen Antonsen

    Espen Antonsen December 16th, 2008 @ 09:09 PM

    +1 This results in rails not understanding that my join tables are included thus querying the DB for each value from the joined tables.

  • Frederick Cheung

    Frederick Cheung December 20th, 2008 @ 10:52 PM

    • State changed from “new” to “wontfix”

    I haven't found this useful in many realworld situations. Code from patch extracted into a plugin available here

  • Dan Pickett

    Dan Pickett April 6th, 2009 @ 07:49 PM

    I'd actually like to see this in core - I just had a valid use case for it when I wanted to concatenate strings found in sepearate tables.

    While the plugin is useful, I don't want to create unnecessary dependencies when I believe this should actually be a feature within core.

    You should be able to derive columns in a finder ubiquitously.


  • Paul Barry

    Paul Barry June 27th, 2009 @ 05:33 AM

    Would also like to see this in code


  • Paul Barry

    Paul Barry June 27th, 2009 @ 05:34 AM


    yeah for not being able to edit comments :(

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=""></a>


Referenced by