aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-10-30 22:06:12 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-10-30 22:06:12 +0900
commit13c5aa818e9284fe30f83469b340e579195bda3f (patch)
tree906e0f4c28b18f80351e45e20abb13193ceff1e5 /activerecord/lib/active_record/reflection.rb
parent46a7b2e20c24f90591495f28786774132f324dbc (diff)
downloadrails-13c5aa818e9284fe30f83469b340e579195bda3f.tar.gz
rails-13c5aa818e9284fe30f83469b340e579195bda3f.tar.bz2
rails-13c5aa818e9284fe30f83469b340e579195bda3f.zip
`source_type_scope` should respect correct table alias
`join_scopes` in `PolymorphicReflection` is passed aliased `table`, so it should be respected for `source_type_scope`. Closes #13969. Fixes #13920. Fixes #15190.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb10
1 files changed, 3 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 8633809757..87bfd75bca 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -839,10 +839,6 @@ module ActiveRecord
source_reflection.join_scopes(table, predicate_builder) + super
end
- def source_type_scope
- through_reflection.klass.where(foreign_type => options[:source_type])
- end
-
def has_scope?
scope || options[:source_type] ||
source_reflection.has_scope? ||
@@ -1011,15 +1007,15 @@ module ActiveRecord
def join_scopes(table, predicate_builder) # :nodoc:
scopes = @previous_reflection.join_scopes(table, predicate_builder) + super
- scopes << @previous_reflection.source_type_scope
+ scopes << build_scope(table, predicate_builder).instance_exec(nil, &source_type_scope)
end
def constraints
- @reflection.constraints + [source_type_info]
+ @reflection.constraints + [source_type_scope]
end
private
- def source_type_info
+ def source_type_scope
type = @previous_reflection.foreign_type
source_type = @previous_reflection.options[:source_type]
lambda { |object| where(type => source_type) }