From 18fe96cc168927a6508478f9ad127d57c1ad56dd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 17 May 2013 15:39:39 -0700 Subject: stop doing assingments in an iterator --- .../associations/join_dependency/join_association.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') 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 e4d17451dc..b81aecb4e5 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -106,12 +106,16 @@ module ActiveRecord ] end - scope_chain_items.each do |item| + 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 - constraint = constraint.and(item.arel.constraints) unless item.arel.constraints.empty? + if item.arel.constraints.empty? + chain + else + chain.and(item.arel.constraints) + end end manager.from(join(table, constraint)) -- cgit v1.2.3