File tree Expand file tree Collapse file tree 4 files changed +18
-2
lines changed
lib/active_record/associations Expand file tree Collapse file tree 4 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -81,9 +81,9 @@ def construct_join_attributes(*records)
81
81
# to try to properly support stale-checking for nested associations.
82
82
def stale_state
83
83
if through_reflection . belongs_to?
84
- Array ( through_reflection . foreign_key ) . map do |foreign_key_column |
84
+ Array ( through_reflection . foreign_key ) . filter_map do |foreign_key_column |
85
85
owner [ foreign_key_column ] && owner [ foreign_key_column ] . to_s
86
- end
86
+ end . presence
87
87
end
88
88
end
89
89
Original file line number Diff line number Diff line change @@ -284,6 +284,20 @@ def test_strict_loading_with_has_many_through_cascade_down_to_middle_records
284
284
end
285
285
end
286
286
287
+ def test_strict_loading_with_has_one_through_does_not_prevent_creation_of_association
288
+ firm = Firm . new ( name : "SuperFirm" ) . tap ( &:strict_loading! )
289
+ computer = Computer . new ( extendedWarranty : 1 ) . tap ( &:strict_loading! )
290
+
291
+ computer . firm = firm
292
+ computer . developer . name = "Joe"
293
+ firm . lead_developer = computer . developer
294
+
295
+ assert_nothing_raised do
296
+ computer . save!
297
+ end
298
+ end
299
+
300
+
287
301
def test_preload_audit_logs_are_strict_loading_because_parent_is_strict_loading
288
302
developer = Developer . first
289
303
Original file line number Diff line number Diff line change 2
2
3
3
class Computer < ActiveRecord ::Base
4
4
belongs_to :developer , foreign_key : "developer"
5
+ has_one :firm , through : :developer
5
6
end
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ def find_most_recent
38
38
accepts_nested_attributes_for :projects
39
39
40
40
has_and_belongs_to_many :shared_computers , class_name : "Computer"
41
+ has_many :computers , foreign_key : :developer
41
42
42
43
has_and_belongs_to_many :projects_extended_by_name ,
43
44
-> { extending ( ProjectsAssociationExtension ) } ,
You can’t perform that action at this time.
0 commit comments