File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
lib/active_record/associations Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -259,10 +259,10 @@ def include?(record)
259
259
klass = reflection . klass
260
260
return false unless record . is_a? ( klass )
261
261
262
- if record . new_record?
263
- include_in_memory? ( record )
264
- elsif loaded?
262
+ if loaded?
265
263
target . include? ( record )
264
+ elsif record . new_record?
265
+ include_in_memory? ( record )
266
266
else
267
267
record_id = klass . composite_primary_key? ? klass . primary_key . zip ( record . id ) . to_h : record . id
268
268
scope . exists? ( record_id )
Original file line number Diff line number Diff line change @@ -636,6 +636,14 @@ def test_does_not_raise_on_eager_loading_a_habtm_relation_if_strict_loading_by_d
636
636
end
637
637
end
638
638
639
+ def test_does_not_raise_when_checking_if_new_record_included_in_eager_loaded_habtm_relation
640
+ Developer . first . projects << Project . first
641
+
642
+ developer = Developer . includes ( :projects ) . strict_loading . first
643
+
644
+ assert_nothing_raised { developer . projects . include? ( Project . new ) }
645
+ end
646
+
639
647
def test_strict_loading_violation_raises_by_default
640
648
assert_equal :raise , ActiveRecord . action_on_strict_loading_violation
641
649
You can’t perform that action at this time.
0 commit comments