diff options
author | eileencodes <eileencodes@gmail.com> | 2014-09-02 14:13:32 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2014-09-04 08:16:13 -0400 |
commit | 0b6358beb417f69c47edd93d099906cc818855ee (patch) | |
tree | 994cb4b82fe64f2de02b6a17d0d15ca27ecf0712 /activerecord/lib/active_record/reflection.rb | |
parent | b8fbcc0787dde662049794ea4555c8aa52847843 (diff) | |
download | rails-0b6358beb417f69c47edd93d099906cc818855ee.tar.gz rails-0b6358beb417f69c47edd93d099906cc818855ee.tar.bz2 rails-0b6358beb417f69c47edd93d099906cc818855ee.zip |
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.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index c0deb76a33..6b5a592ee5 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -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 |