Skip to content

Commit 833109c

Browse files
committed
Merge pull request rails#14390 from huoxito/true-touch
Still touch associations when theres no timestamp
2 parents e94e6c2 + ea3a73e commit 833109c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

activerecord/lib/active_record/persistence.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ def touch(*names)
455455
changed_attributes.except!(*changes.keys)
456456
primary_key = self.class.primary_key
457457
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
458+
else
459+
true
458460
end
459461
end
460462

activerecord/test/cases/associations/belongs_to_associations_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ def test_belongs_to_with_touch_option_on_touch
340340
assert_queries(1) { line_item.touch }
341341
end
342342

343+
def test_belongs_to_with_touch_option_on_touch_without_updated_at_attributes
344+
assert !LineItem.column_names.include?("updated_at")
345+
346+
line_item = LineItem.create!
347+
invoice = Invoice.create!(line_items: [line_item])
348+
initial = invoice.updated_at
349+
line_item.touch
350+
351+
refute_equal initial, invoice.reload.updated_at
352+
end
353+
343354
def test_belongs_to_with_touch_option_on_touch_and_removed_parent
344355
line_item = LineItem.create!
345356
Invoice.create!(line_items: [line_item])

0 commit comments

Comments
 (0)