aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-08-25 16:36:55 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-08-25 16:36:55 +0900
commit1a723c65bbe91ad969b67416233d20eff6d2a46a (patch)
treea9f47b50453696ffcb8c41d1c28494cc4f23af63 /activerecord/lib/active_record/relation.rb
parentcb5af0d750198739d85b99aecd2f69927ec42e6a (diff)
downloadrails-1a723c65bbe91ad969b67416233d20eff6d2a46a.tar.gz
rails-1a723c65bbe91ad969b67416233d20eff6d2a46a.tar.bz2
rails-1a723c65bbe91ad969b67416233d20eff6d2a46a.zip
Should work inverse association when eager loading
This regression was caused by caa178c1. The block for `set_inverse_instance` should also be passed to join dependency. Fixes #30402.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r--activerecord/lib/active_record/relation.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index d319978930..012bc838b1 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -566,7 +566,7 @@ module ActiveRecord
relation = self
if eager_loading?
- find_with_associations { |rel| relation = rel }
+ find_with_associations { |rel, _| relation = rel }
end
conn = klass.connection
@@ -660,7 +660,19 @@ module ActiveRecord
def exec_queries(&block)
skip_query_cache_if_necessary do
- @records = eager_loading? ? find_with_associations.freeze : @klass.find_by_sql(arel, &block).freeze
+ @records =
+ if eager_loading?
+ find_with_associations do |relation, join_dependency|
+ if ActiveRecord::NullRelation === relation
+ []
+ else
+ rows = connection.select_all(relation.arel, "SQL")
+ join_dependency.instantiate(rows, &block)
+ end.freeze
+ end
+ else
+ klass.find_by_sql(arel, &block).freeze
+ end
preload = preload_values
preload += includes_values unless eager_loading?