Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Allow :select option with join-based include

#1060

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

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

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Rob Anderton
    Rob Anderton

    +1

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

    September 19th, 2008 @ 06:04 PM

  2. Chris Heald
    Chris Heald

    +1

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

    To illustrate the problem:

    Schema

    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">

    October 7th, 2008 @ 01:10 AM

  3. Pratik
    Pratik
    • Milestone cleared.

    Let's tackle this post 2.2

    October 7th, 2008 @ 01:56 PM

  4. John
    John

    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?

    December 5th, 2008 @ 11:12 AM

  5. Espen Antonsen
    Espen Antonsen

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

    December 16th, 2008 @ 09:09 PM

  6. Frederick Cheung
    Frederick Cheung
    • 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

    December 20th, 2008 @ 10:52 PM

  7. Dan Pickett
    Dan Pickett

    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.

    +1

    April 6th, 2009 @ 07:49 PM

  8. Paul Barry
    Paul Barry

    Would also like to see this in code

    +1

    June 27th, 2009 @ 05:33 AM

  9. Paul Barry
    Paul Barry

    s/code/core

    yeah for not being able to edit comments :(

    June 27th, 2009 @ 05:34 AM