diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-11-06 08:29:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-06 08:29:40 +0900 |
commit | ffc1ed9bd54f3cf746f7ddf798e000fc025edef6 (patch) | |
tree | 899877d845bcc4a6d0cd0c3b73070801205faa16 /activerecord/lib/active_record | |
parent | e0bef22665f93e88f6b2f3ac6bd55543ed0d6343 (diff) | |
download | rails-ffc1ed9bd54f3cf746f7ddf798e000fc025edef6.tar.gz rails-ffc1ed9bd54f3cf746f7ddf798e000fc025edef6.tar.bz2 rails-ffc1ed9bd54f3cf746f7ddf798e000fc025edef6.zip |
`scoping` should respect current class and STI constraint (#29199)
A relation includes `klass`, so it can not be used as it is if current
class is different from `current_scope.klass`. It should be created new
relation by current class to respect the klass and STI constraint.
Fixes #17603.
Fixes #23576.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 6fa096c1fe..310af72c41 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -24,8 +24,14 @@ module ActiveRecord # You can define a scope that applies to all finders using # {default_scope}[rdoc-ref:Scoping::Default::ClassMethods#default_scope]. def all + current_scope = self.current_scope + if current_scope - current_scope.clone + if self == current_scope.klass + current_scope.clone + else + relation.merge!(current_scope) + end else default_scoped end |