Permalink
Browse files

make sure scope_chain_items has consistent types

  • Loading branch information...
1 parent 9eb0cd2 commit e70da0e1a37ca396028f24816ea2198a06df25c0 @tenderlove tenderlove committed Jul 16, 2013
Showing with 9 additions and 7 deletions.
  1. +9 −7 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -97,22 +97,24 @@ def join_to(manager)
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

0 comments on commit e70da0e

Please sign in to comment.