This project is archived and is in readonly mode.
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 September 19th, 2008 @ 06:04 PM
+1
This is very handy: something I've needed quite a few times.
-
Chris Heald October 7th, 2008 @ 01:10 AM
+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">
-
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 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 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 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.
+1
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>
People watching this ticket
Attachments
Tags
Referenced by
- 975 ActiveRecord: SELECT clause breaks when INCLUDE added There's a newer ticket #1060 with a patch that supposedly...
- 1110 Eager loading regression for find with :includes of associations already :included by the parent association http://rails.lighthouseapp.com/p... which allows :select...
- 1110 Eager loading regression for find with :includes of associations already :included by the parent association If Fred's #1060 patch gets merged, please merge this as w...
- 1110 Eager loading regression for find with :includes of associations already :included by the parent association If Fred's #1060 patch gets merged, please merge this as w...
- 1110 Eager loading regression for find with :includes of associations already :included by the parent association If Fred's #1060 patch gets merged, please merge this as w...
- 1110 Eager loading regression for find with :includes of associations already :included by the parent association Hmm, I don't like #1060 for 2.2 just because it makes :se...
- 976 Calculated columns with eager loading Not convinced of the real world usefulness. I had a very ...
- 77 ActiveRecord: :select is wiped when doing a join Not convinced of the real world usefulness. #1060 is a si...