diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-07-18 10:39:09 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-07-19 00:50:40 +0900 |
commit | 9aa04315febfb37b50f52471a2837c40313a2d5f (patch) | |
tree | 2face8dcc9cc116d9e1c1d20e052e9d95e1ec080 /activerecord/lib/active_record/associations/preloader | |
parent | d13f54d50a166d49c683f79d49341185788faed8 (diff) | |
download | rails-9aa04315febfb37b50f52471a2837c40313a2d5f.tar.gz rails-9aa04315febfb37b50f52471a2837c40313a2d5f.tar.bz2 rails-9aa04315febfb37b50f52471a2837c40313a2d5f.zip |
Fix unscoping `default_scope` for `Preloader`
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/association.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 85343040db..698fd29beb 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -114,8 +114,18 @@ module ActiveRecord @reflection_scope ||= reflection.scope_for(klass) end + def klass_scope + current_scope = klass.current_scope + + if current_scope && current_scope.empty_scope? + klass.unscoped + else + klass.default_scoped + end + end + def build_scope - scope = klass.default_scoped + scope = klass_scope if reflection.type scope.where!(reflection.type => model.base_class.sti_name) |