This project is archived and is in readonly mode.
Finder methods ignore :include in has_many :through
-
JackC
- Tag changed from :include, :through, finder to :include, :through, eagerloading, eager_loading, find, finder
This is also an issue in 2.3 RC1.
I've also found that all works even the find(:all) doesn't.
It seems to be fixable by inserting the following line at line 52.
options[:include] = @reflection.options[:include]But I don't know enough about the ActiveRecord internals to know if this will break something.
-
JackC
Line 52 of active_record/associations/association_collection.rb that is.
-
CancelProfileIsBroken
- Tag changed from :include, :through, eagerloading, eager_loading, find, finder to :include, :through, bugmash, eagerloading, eager_loading, find, finder
-
railsbob
verified
This error is reproducible. The error is caused because options[:include] was assigned nil in has_many_through_association.rb.
def construct_find_options!(options) options[:select] = construct_select(options[:select]) options[:from] ||= construct_from options[:joins] = construct_joins(options[:joins]) options[:include] = @reflection.source_reflection.options[:include] if options[:include].nil? endoptions[:include] should not be nil, because the reverse_merge! prohibits assignment from @reflection.options[:include] in merge_options_from_reflection!(options) method (association_proxy.rb), even if the value is nil.
The solution is not to have options[:include] if the value is nil and appropriate :include options are picked from reflection.I have attached a patch with corresponding test, which fixed the issue.
-
Hugo Peixoto
+1 railsbob's patch works fine in both 2-3-stable and master, and without the fix the test fails.
-
Rizwan Reza
verified
+1 The patch works perfectly under master and 2-3-stable. All tests pass.
-
David Trasbo
+1
Bug verified to be reproducible. Patch applies cleanly to edge Rails and all tests are passing.
-
Repository
- State changed from new to resolved
(from [076ca48bd649ddea4dd1a320879c03a9fe7a0a6d]) Ensure hm:t#find does not assign nil to :include [#1845 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/076ca48bd649ddea4dd1a320879c03... -
Repository
(from [80d8608102cce64805e7573f6b97d8561f7f11ea]) Ensure hm:t#find does not assign nil to :include [#1845 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/80d8608102cce64805e7573f6b97d8... -
CancelProfileIsBroken
- Tag changed from :include, :through, bugmash, eagerloading, eager_loading, find, finder to :include, :through, eagerloading, eager_loading, find, finder
- Milestone cleared.
-
Josh N. Abbott
Has this issue really been resolved? I'm running Rails 2.3.4 and when I try to load a has_many :through association, the construct_find_options! method doesn't get called. The find_target method is what gets called and in spite of the fact that it appears that the :include option is getting passed to the subsequently called 'find' method, the associations are being ignored.
Another odd thing is that when I call #count on the association everything loads fine.
So the question is, did this patch actually solve the original problem the ticket was opened for? It seems to me that it didn't.
