This project is archived and is in readonly mode.
[PATCH] SQL generated by find ignores :include option
-
Emery Finkelstein
I've done a little more investigation into the issue and made the following observations.
Giving the same options the named scope should have to scoped works as expected.
eg:Item.scoped(:include => :collection_sets, :order => 'items.name', :conditions => {:'collection_sets.collection_id' => c})Works as expected when c is defined as either a CollectionSet object or an integer.
A result of this is that I could create a lambda or Proc or method that just calls an anonymous scope, but this work around cannot be chained.
proxy_options for the named scope includes :include.
Item.in_collection(2).proxy_options => {:include=>:collection_sets, :order=>"items.name", :conditions=>{:"collection_sets.collection_id"=> 2} } -
CancelProfileIsBroken
- Tag changed from 2.3.3, :include, activerecord, error, ignored, named_scope, sql to 2.3.3, :include, activerecord, bugmash, error, ignored, named_scope, sql
-
Elad Meidar
+1 verified on 2-3-stable, i tried to follow up
named_scope.rband try to point to where exactly the:includeoption is dropped/ignored when set within a lambda, but couldn't find any pointers.. -
Luciano G. Panaro
+1 verified - will try to write a test for it
-
Luciano G. Panaro
I understand that the options of a scope such as conditions are passed directly to #find. So in this case it would be a bug in #find rather than scopes themselves. This for example did not work either:
def self.test(c) self.find :all, :include => :collection_sets, :conditions => { :'collection_sets.id' => c } end -
John Trupiano
+1 verified
I have attached a test case that demonstrates the error on the #find method (as per Luciano's finding).
-
John Trupiano
So it turns out the culprit was using symbols for keys in the conditions hash. Had you conversely used a string instead, this query would have worked.
I have updated my previous patch with the one line fix to associations.rb to allow symbols as keys.
-
Elad Meidar
+1 verified on 2-3-stable and Master, patch however, applies cleanly only on 2-3-stable.
i've attached a patch for master, (credits are mine, i have no idea how to notate them to someone else, sorry). -
sr.iniv.t
+1 verified.
Both patches apply clean (John's on 2-3-stable, Elad's on master) and all tests pass.
-
CancelProfileIsBroken
- Tag changed from 2.3.3, :include, activerecord, bugmash, error, ignored, named_scope, sql to 2.3.3, :include, activerecord, bugmash, bugmash-review, error, ignored, named_scope, sql
-
CancelProfileIsBroken
- Tag changed from 2.3.3, :include, activerecord, bugmash, bugmash-review, error, ignored, named_scope, sql to 2.3.3, :include, activerecord, bugmash-review, error, ignored, named_scope, sql
-
John Trupiano
- Title changed from named_scope ignores :include option to [PATCH] SQL generated by find ignores :include option
This patch is good to be applied. Just changing the name to include PATCH and better describe the actual patch (original bug report was just a derivative manifestation of the real bug).
-
iGEL
- Tag changed from 2.3.3, :include, activerecord, bugmash-review, error, ignored, named_scope, sql to 2-3-stable, 2.3, 2.3.5, 3.0, :include, activerecord, bugmash-review, error, ignored, named_scope, patch, sql
Any news?
-
John Trupiano
I would love to see this one applied. Duplicate bugs (e.g. https://rails.lighthouseapp.com/projects/8994/tickets/3316-has_many... ) continue to be reported.
-
Henrik Nyh
+1, just ran into this on 2.3.5 (after upgrading from 2.1.2 where it worked).
-
Henrik Nyh
Made a monkeypatch initializer that can be used until Johns patch is merged: http://gist.github.com/277141
-
Rizwan Reza
- Tag changed from 2-3-stable, 2.3, 2.3.5, 3.0, :include, activerecord, bugmash-review, error, ignored, named_scope, patch, sql to 2-3-stable, 2.3, 2.3.5, 3.0, :include, activerecord, bugmash, error, ignored, named_scope, patch, sql
-
Santiago Pastorino
- State changed from new to open
- Tag changed from 2-3-stable, 2.3, 2.3.5, 3.0, :include, activerecord, bugmash, error, ignored, named_scope, patch, sql to 2-3-stable, 23, 235, 30, activerecord, bugmash, error, ignored, include, named_scope, patch, sql
- Importance changed from to
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.
-
Santiago Pastorino
- State changed from open to stale
