Permalink
Browse files

use Relation#merge to combine scope chain items

  • Loading branch information...
1 parent e70da0e commit 5b83f46a1907f258cae044f8d2e83a7fae15b7b5 @tenderlove tenderlove committed Jul 16, 2013
Showing with 6 additions and 6 deletions.
  1. +6 −6 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -114,12 +114,12 @@ def join_to(manager)
scope_chain_items.concat [reflection.klass.send(:build_default_scope)].compact
- constraint = scope_chain_items.inject(constraint) do |chain, item|
- if item.arel.constraints.empty?
- chain
- else
- chain.and(item.arel.constraints)
- end
+ rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
+ left.merge right
+ end
+
+ if rel && !rel.arel.constraints.empty?
+ constraint = constraint.and rel.arel.constraints
end
manager.from(join(table, constraint))

0 comments on commit 5b83f46

Please sign in to comment.