File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -689,7 +689,7 @@ def inspect
689
689
end
690
690
691
691
def empty_scope? # :nodoc:
692
- @values == klass . unscoped . values
692
+ ! null_relation? && @values == klass . unscoped . values
693
693
end
694
694
695
695
def has_limit_or_offset? # :nodoc:
@@ -721,6 +721,10 @@ def load_records(records)
721
721
@loaded = true
722
722
end
723
723
724
+ def null_relation? # :nodoc:
725
+ is_a? ( NullRelation )
726
+ end
727
+
724
728
private
725
729
def already_in_scope?
726
730
@delegate_to_klass && begin
@@ -770,7 +774,7 @@ def exec_queries(&block)
770
774
@records =
771
775
if eager_loading?
772
776
apply_join_dependency do |relation , join_dependency |
773
- if ActiveRecord :: NullRelation === relation
777
+ if relation . null_relation?
774
778
[ ]
775
779
else
776
780
relation = join_dependency . apply_column_aliases ( relation )
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def default_scoped(scope = relation) # :nodoc:
58
58
end
59
59
60
60
def default_extensions # :nodoc:
61
- if scope = current_scope || build_default_scope
61
+ if scope = scope_for_association || build_default_scope
62
62
scope . extensions
63
63
else
64
64
[ ]
Original file line number Diff line number Diff line change @@ -421,6 +421,18 @@ def test_nested_scope_finder
421
421
end
422
422
end
423
423
424
+ def test_none_scoping
425
+ Comment . none . scoping do
426
+ assert_equal 2 , @welcome . comments . count
427
+ assert_equal "a comment..." , @welcome . comments . what_are_you
428
+ end
429
+
430
+ Comment . where ( "1=1" ) . scoping do
431
+ assert_equal 2 , @welcome . comments . count
432
+ assert_equal "a comment..." , @welcome . comments . what_are_you
433
+ end
434
+ end
435
+
424
436
def test_should_maintain_default_scope_on_associations
425
437
magician = BadReference . find ( 1 )
426
438
assert_equal [ magician ] , people ( :michael ) . bad_references
@@ -461,4 +473,16 @@ def test_nested_scope_finder
461
473
assert_equal "a category..." , @welcome . categories . what_are_you
462
474
end
463
475
end
476
+
477
+ def test_none_scoping
478
+ Category . none . scoping do
479
+ assert_equal 2 , @welcome . categories . count
480
+ assert_equal "a category..." , @welcome . categories . what_are_you
481
+ end
482
+
483
+ Category . where ( "1=1" ) . scoping do
484
+ assert_equal 2 , @welcome . categories . count
485
+ assert_equal "a category..." , @welcome . categories . what_are_you
486
+ end
487
+ end
464
488
end
You can’t perform that action at this time.
0 commit comments