From e70da0e1a37ca396028f24816ea2198a06df25c0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 16 Jul 2013 11:21:46 -0700 Subject: make sure scope_chain_items has consistent types --- .../associations/join_dependency/join_association.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index e0715d9dd1..d1bc64adf6 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -97,22 +97,24 @@ module ActiveRecord constraint = build_constraint(reflection, table, key, foreign_table, foreign_key) - scope_chain_items = scope_chain[i] + scope_chain_items = scope_chain[i].map do |item| + if item.is_a?(Relation) + item + else + ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item) + end + end if reflection.type - scope_chain_items += [ + scope_chain_items.concat [ ActiveRecord::Relation.new(reflection.klass, table) .where(reflection.type => foreign_klass.base_class.name) ] end - scope_chain_items += [reflection.klass.send(:build_default_scope)].compact + scope_chain_items.concat [reflection.klass.send(:build_default_scope)].compact constraint = scope_chain_items.inject(constraint) do |chain, item| - unless item.is_a?(Relation) - item = ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item) - end - if item.arel.constraints.empty? chain else -- cgit v1.2.3