Skip to content

Commit 7ebbe32

Browse files
authored
Merge pull request rails#46688 from rails/revert-46613-strict-loading-build
Revert "Fix: Strict Loading error after initializing association owner with primary key"
2 parents 2c86139 + 3828c87 commit 7ebbe32

File tree

4 files changed

+4
-35
lines changed

4 files changed

+4
-35
lines changed

activerecord/lib/active_record/associations/collection_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def build(attributes = nil, &block)
119119
def concat(*records)
120120
records = records.flatten
121121
if owner.new_record?
122-
loaded!
122+
load_target
123123
concat_records(records)
124124
else
125125
transaction { concat_records(records) }

activerecord/test/cases/associations/join_model_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def test_associating_unsaved_records_with_has_many_through
478478
new_tag = Tag.new(name: "new")
479479

480480
saved_post.tags << new_tag
481-
assert_predicate new_tag, :persisted? # consistent with habtm!
481+
assert new_tag.persisted? # consistent with habtm!
482482
assert_predicate saved_post, :persisted?
483483
assert_includes saved_post.tags, new_tag
484484

activerecord/test/cases/associations_test.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,16 @@ def test_push_followed_by_save_does_not_load_target
157157

158158
def test_push_does_not_lose_additions_to_new_record
159159
josh = Author.new(name: "Josh")
160-
new_post = Post.new(title: "New on Edge", body: "More cool stuff!")
161-
josh.posts << new_post
160+
josh.posts << Post.new(title: "New on Edge", body: "More cool stuff!")
162161
assert_predicate josh.posts, :loaded?
163162
assert_equal 1, josh.posts.size
164-
assert_includes josh.posts, new_post
165163
end
166164

167165
def test_append_behaves_like_push
168166
josh = Author.new(name: "Josh")
169-
new_post = Post.new(title: "New on Edge", body: "More cool stuff!")
170-
josh.posts.append new_post
167+
josh.posts.append Post.new(title: "New on Edge", body: "More cool stuff!")
171168
assert_predicate josh.posts, :loaded?
172169
assert_equal 1, josh.posts.size
173-
assert_includes josh.posts, new_post
174170
end
175171

176172
def test_prepend_is_not_defined

activerecord/test/cases/strict_loading_test.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,33 +162,6 @@ def test_strict_loading_with_reflection_is_ignored_in_validation_context
162162
end
163163
end
164164

165-
def test_strict_loading_on_concat_is_ignored
166-
developer = Developer.first
167-
developer.strict_loading!
168-
169-
assert_nothing_raised do
170-
developer.audit_logs << AuditLog.new(message: "message")
171-
end
172-
end
173-
174-
def test_strict_loading_with_new_record_on_concat_is_ignored
175-
developer = Developer.new(id: Developer.first.id)
176-
developer.strict_loading!
177-
178-
assert_nothing_raised do
179-
developer.audit_logs << AuditLog.new(message: "message")
180-
end
181-
end
182-
183-
def test_strict_loading_with_new_record_on_build_is_ignored
184-
developer = Developer.new(id: Developer.first.id)
185-
developer.strict_loading!
186-
187-
assert_nothing_raised do
188-
developer.audit_logs.build(message: "message")
189-
end
190-
end
191-
192165
def test_strict_loading_has_one_reload
193166
with_strict_loading_by_default(Developer) do
194167
ship = Ship.create!(developer: Developer.first, name: "The Great Ship")

0 commit comments

Comments
 (0)