aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/predicate_builder.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-03-20 20:58:41 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-03-20 21:12:34 +0900
commit4b884fc732c574c40296a2f78816b25a06b64ffe (patch)
tree7db512a56b7296be65b36232892b00687451020d /activerecord/lib/active_record/relation/predicate_builder.rb
parent1835d87fb848fd9f13e43bf16abd41be231b1666 (diff)
downloadrails-4b884fc732c574c40296a2f78816b25a06b64ffe.tar.gz
rails-4b884fc732c574c40296a2f78816b25a06b64ffe.tar.bz2
rails-4b884fc732c574c40296a2f78816b25a06b64ffe.zip
Preprocess association query handling in predicate builder
Currently association query is handled as a postprocess. This has two problems. 1. When `value` is a `Hash`, we need to skip the postprocess using `next`. 2. `can_be_bound?` should return false if `table.associated_with?(column_name)` is true (pass to the postprocess). These are unneeded if preprocessing association query handling.
Diffstat (limited to 'activerecord/lib/active_record/relation/predicate_builder.rb')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb19
1 files changed, 8 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 18ae10a652..ec1861bd85 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -92,7 +92,14 @@ module ActiveRecord
attrs, bvs = associated_predicate_builder(column_name).create_binds_for_hash(value)
result[column_name] = attrs
binds += bvs
- next
+ 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)
+ binds.concat(value.bound_attributes) if value.is_a?(Relation)
when value.is_a?(Relation)
binds += value.bound_attributes
when value.is_a?(Range) && !table.type(column_name).respond_to?(:subtype)
@@ -114,15 +121,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 +153,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)