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,12 +188,8 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def eval_scope(klass, scope, owner)
|
def eval_scope(klass, scope, owner)
|
||||||
if scope.is_a?(Relation)
|
|
||||||
scope
|
|
||||||
else
|
|
||||||
klass.unscoped.instance_exec(owner, &scope)
|
klass.unscoped.instance_exec(owner, &scope)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -728,8 +728,11 @@ module ActiveRecord
|
||||||
through_scope_chain = through_reflection.scope_chain.map(&:dup)
|
through_scope_chain = through_reflection.scope_chain.map(&:dup)
|
||||||
|
|
||||||
if options[:source_type]
|
if options[:source_type]
|
||||||
through_scope_chain.first <<
|
type = foreign_type
|
||||||
through_reflection.klass.where(foreign_type => options[:source_type])
|
source_type = options[:source_type]
|
||||||
|
through_scope_chain.first << lambda { |object|
|
||||||
|
where(type => source_type)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Recursively fill out the rest of the array from the through reflection
|
# Recursively fill out the rest of the array from the through reflection
|
||||||
|
|
Loading…
Reference in a new issue