aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-08-16 05:59:31 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-08-16 05:59:31 -0300
commitc65c1721e2a137c3bb7a877fa4cfb3f78f89401a (patch)
treef8d6c904974827c6045adfd021eb91a1e9c5f573
parentd60f3495be2df097c483e5aab227a8a636a55f4c (diff)
parentc30ff2b971eb6b0b038de20ca91ef9f3a6e460f6 (diff)
downloadrails-c65c1721e2a137c3bb7a877fa4cfb3f78f89401a.tar.gz
rails-c65c1721e2a137c3bb7a877fa4cfb3f78f89401a.tar.bz2
rails-c65c1721e2a137c3bb7a877fa4cfb3f78f89401a.zip
Merge pull request #26117 from kamipo/make_association_quary_to_preparable_step1
Make association queries to preparable: Step 1
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb22
1 files changed, 11 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 9d6fc9f702..0c8282de8e 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -77,7 +77,7 @@ module ActiveRecord
if value.is_a?(Hash)
associated_predicate_builder(key).expand_from_hash(value)
else
- expand(key, value)
+ build(table.arel_attribute(key), value)
end
end
end
@@ -92,6 +92,7 @@ module ActiveRecord
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 value.is_a?(Range) && !table.type(column_name).respond_to?(:subtype)
@@ -113,6 +114,15 @@ 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]
@@ -120,16 +130,6 @@ module ActiveRecord
private
- def expand(column, value)
- # 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)
- value = AssociationQueryHandler.value_for(table, column, value) if table.associated_with?(column)
- build(table.arel_attribute(column), value)
- end
-
def associated_predicate_builder(association_name)
self.class.new(table.associated_table(association_name))
end