File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed
lib/active_record/associations Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change
1
+ * Fix an issue where the IDs reader method did not return expected results
2
+ for preloaded associations in models using composite primary keys.
3
+
4
+ * Jay Ang*
5
+
1
6
* Allow to configure ` strict_loading_mode ` globally or within a model.
2
7
3
8
Defaults to ` :all ` , can be changed to ` :n_plus_one_only ` .
Original file line number Diff line number Diff line change @@ -50,11 +50,11 @@ def writer(records)
50
50
# Implements the ids reader method, e.g. foo.item_ids for Foo.has_many :items
51
51
def ids_reader
52
52
if loaded?
53
- target . pluck ( reflection . association_primary_key )
53
+ target . pluck ( * reflection . association_primary_key )
54
54
elsif !target . empty?
55
- load_target . pluck ( reflection . association_primary_key )
55
+ load_target . pluck ( * reflection . association_primary_key )
56
56
else
57
- @association_ids ||= scope . pluck ( reflection . association_primary_key )
57
+ @association_ids ||= scope . pluck ( * reflection . association_primary_key )
58
58
end
59
59
end
60
60
Original file line number Diff line number Diff line change @@ -3234,6 +3234,12 @@ def test_key_ensuring_owner_was_is_valid_when_dependent_option_is_destroy_async
3234
3234
MESSAGE
3235
3235
end
3236
3236
3237
+ def test_ids_reader_on_preloaded_association_with_composite_primary_key
3238
+ great_author = cpk_authors ( :cpk_great_author )
3239
+
3240
+ assert_equal great_author . books . ids , Cpk ::Author . preload ( :books ) . find ( great_author . id ) . book_ids
3241
+ end
3242
+
3237
3243
private
3238
3244
def force_signal37_to_load_all_clients_of_firm
3239
3245
companies ( :first_firm ) . clients_of_firm . load_target
You can’t perform that action at this time.
0 commit comments