mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Always add lambda to scope chain to eliminate branch in eval_scope
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.
This commit is contained in:
parent
b8fbcc0787
commit
0b6358beb4
2 changed files with 6 additions and 7 deletions
|
@ -188,11 +188,7 @@ module ActiveRecord
|
|||
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
|
||||
|
|
|
@ -728,8 +728,11 @@ module ActiveRecord
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue