aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-03-27 18:21:41 -0400
committerGitHub <noreply@github.com>2017-03-27 18:21:41 -0400
commit3b474da4e6d623bf10b09bbb96b292c6dcf795af (patch)
treeb4f8d1f2430cde9a94d1613bb38a9d14b324724e /activerecord
parentc1faca6333abe4b938b98fedc8d1f47b88209ecf (diff)
parente1533d2d5a631859ea47702ab64c11bba420b5b8 (diff)
downloadrails-3b474da4e6d623bf10b09bbb96b292c6dcf795af.tar.gz
rails-3b474da4e6d623bf10b09bbb96b292c6dcf795af.tar.bz2
rails-3b474da4e6d623bf10b09bbb96b292c6dcf795af.zip
Merge pull request #28488 from kamipo/preprocess_association_query_handling
Preprocess association query handling in predicate builder
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb21
1 files changed, 8 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 18ae10a652..fca914aedd 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -87,14 +87,19 @@ module ActiveRecord
binds = []
attributes.each do |column_name, value|
+ binds.concat(value.bound_attributes) if value.is_a?(Relation)
case
when value.is_a?(Hash) && !table.has_column?(column_name)
attrs, bvs = associated_predicate_builder(column_name).create_binds_for_hash(value)
result[column_name] = attrs
binds += bvs
- next
- when value.is_a?(Relation)
- binds += value.bound_attributes
+ when table.associated_with?(column_name)
+ # Find the foreign key when using queries such as:
+ # Post.where(author: author)
+ #
+ # For polymorphic relationships, find the foreign key and type:
+ # PriceEstimate.where(estimate_of: treasure)
+ result[column_name] = AssociationQueryHandler.value_for(table, column_name, value)
when value.is_a?(Range) && !table.type(column_name).respond_to?(:subtype)
first = value.begin
last = value.end
@@ -114,15 +119,6 @@ module ActiveRecord
binds << build_bind_param(column_name, value)
end
end
-
- # Find the foreign key when using queries such as:
- # Post.where(author: author)
- #
- # For polymorphic relationships, find the foreign key and type:
- # PriceEstimate.where(estimate_of: treasure)
- if table.associated_with?(column_name)
- result[column_name] = AssociationQueryHandler.value_for(table, column_name, value)
- end
end
[result, binds]
@@ -155,7 +151,6 @@ module ActiveRecord
end
def can_be_bound?(column_name, value)
- return if table.associated_with?(column_name)
case value
when Array, Range
table.type(column_name).respond_to?(:subtype)