From 4e5c2ccc1d97f0c18834f616fc219be6b1531bde Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 30 Jan 2017 16:36:17 -0800 Subject: Avoid lambda scopes when possible Lambda scopes require a bunch more work. Ideally the `scope` list would be a homogeneous collection. In this case, the reflection knows how to construct the right reflection for this join, so lets just construct that relation rather than instance execing to figure it out later. --- activerecord/lib/active_record/reflection.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index d923050822..81ec4924b0 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -807,9 +807,7 @@ module ActiveRecord end def source_type_scope - type = foreign_type - source_type = options[:source_type] - lambda { |object| where(type => source_type) } + through_reflection.klass.where(foreign_type => options[:source_type]) end def has_scope? -- cgit v1.2.3