This project is archived and is in readonly mode.
Allow :select option with join-based include
-
Rob Anderton
+1
This is very handy: something I've needed quite a few times.
-
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"> -
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?
-
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.
-
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
-
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
-
Paul Barry
Would also like to see this in code
+1
-
Paul Barry
s/code/core
yeah for not being able to edit comments :(
