File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
lib/active_record/attribute_methods Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -129,12 +129,13 @@ def get_primary_key(base_name) # :nodoc:
129
129
# Project.primary_key # => "foo_id"
130
130
def primary_key = ( value )
131
131
@primary_key = if value . is_a? ( Array )
132
- @composite_primary_key = true
133
132
include CompositePrimaryKey
134
133
@primary_key = value . map { |v | -v . to_s } . freeze
135
134
elsif value
136
135
-value . to_s
137
136
end
137
+
138
+ @composite_primary_key = value . is_a? ( Array )
138
139
@attributes_builder = nil
139
140
end
140
141
Original file line number Diff line number Diff line change @@ -256,6 +256,17 @@ def test_assign_id_raises_error_if_primary_key_doesnt_exist
256
256
assert_raises ( ActiveModel ::MissingAttributeError ) { dashboard . id = "1" }
257
257
end
258
258
259
+ def test_reconfiguring_primary_key_resets_composite_primary_key
260
+ klass = Class . new ( ActiveRecord ::Base ) do
261
+ self . table_name = "cpk_books"
262
+ end
263
+
264
+ assert_predicate klass , :composite_primary_key?
265
+
266
+ klass . primary_key = :id
267
+ assert_not_predicate klass , :composite_primary_key?
268
+ end
269
+
259
270
def composite_primary_key_is_false_for_a_non_cpk_model
260
271
assert_not_predicate Dashboard , :composite_primary_key?
261
272
end
You can’t perform that action at this time.
0 commit comments