diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-06 12:00:17 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-06 12:00:17 +0900 |
commit | 0856f7c744e631b6efafbb14d01e60bbfaa593f5 (patch) | |
tree | f360e33010b419387e15722854467167b8ab7fe3 /activerecord | |
parent | 56b4fdb52bd327d42aec9ee3dcea01298aafe945 (diff) | |
download | rails-0856f7c744e631b6efafbb14d01e60bbfaa593f5.tar.gz rails-0856f7c744e631b6efafbb14d01e60bbfaa593f5.tar.bz2 rails-0856f7c744e631b6efafbb14d01e60bbfaa593f5.zip |
There is no need to check `null_relation?` in `empty_scope?`
`values[:extending]` includes `NullRelation` if `null_relation?`.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 3 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 4 |
3 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index c1cdad9c87..cd62b0b881 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -689,7 +689,7 @@ module ActiveRecord end def empty_scope? # :nodoc: - !null_relation? && @values == klass.unscoped.values + @values == klass.unscoped.values end def has_limit_or_offset? # :nodoc: diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 00a7b3841f..90b208092f 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -101,6 +101,9 @@ module ActiveRecord relation.merge!(relation) assert_predicate relation, :empty_scope? + + assert_not_predicate NullPost.all, :empty_scope? + assert_not_predicate FirstPost.all, :empty_scope? end def test_bad_constants_raise_errors diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 61e5f14100..395b534c63 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -203,6 +203,10 @@ end class SubAbstractStiPost < AbstractStiPost; end +class NullPost < Post + default_scope { none } +end + class FirstPost < ActiveRecord::Base self.inheritance_column = :disabled self.table_name = "posts" |