Skip to content

Commit

Permalink
Always add lambda to scope chain to eliminate branch in eval_scope
Browse files Browse the repository at this point in the history
We convert all other scopes to lambda's so it makes sense that we should
always returns a lambda on a ThroughReflection as well. This eliminates
the need to check if the scope is a Relation.
  • Loading branch information
eileencodes authored and sgrif committed Dec 23, 2014
1 parent b0199b8 commit 6ecf6bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Expand Up @@ -143,11 +143,7 @@ def table_name_for(reflection, klass, refl)
end

def eval_scope(klass, scope, owner)
if scope.is_a?(Relation)
scope
else
klass.unscoped.instance_exec(owner, &scope)
end
klass.unscoped.instance_exec(owner, &scope)
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions activerecord/lib/active_record/reflection.rb
Expand Up @@ -609,8 +609,11 @@ def scope_chain
through_scope_chain = through_reflection.scope_chain.map(&:dup)

if options[:source_type]
through_scope_chain.first <<
through_reflection.klass.where(foreign_type => options[:source_type])
type = foreign_type
source_type = options[:source_type]
through_scope_chain.first << lambda { |object|
where(type => source_type)
}
end

# Recursively fill out the rest of the array from the through reflection
Expand Down

0 comments on commit 6ecf6bb

Please sign in to comment.