mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Prevented belongs_to: touch propagating up if there are no changes being saved
This commit is contained in:
parent
5508a3e5ca
commit
713fc39d93
3 changed files with 16 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
|||
* Change belongs_to touch to be consistent with timestamp updates
|
||||
|
||||
If a model is set up with a belongs_to: touch relatinoship the parent
|
||||
record will only be touched if the record was modified. This makes it
|
||||
consistent with timestamp updating on the record itself.
|
||||
|
||||
*Brock Trappitt*
|
||||
|
||||
* Fixed the inferred table name of a HABTM auxiliar table inside a schema.
|
||||
|
||||
Fixes #14824
|
||||
|
|
|
@ -103,7 +103,7 @@ module ActiveRecord::Associations::Builder
|
|||
BelongsTo.touch_record(record, foreign_key, n, touch)
|
||||
}
|
||||
|
||||
model.after_save callback
|
||||
model.after_save callback, if: :changed?
|
||||
model.after_touch callback
|
||||
model.after_destroy callback
|
||||
end
|
||||
|
|
|
@ -369,6 +369,13 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|||
assert_queries(2) { line_item.update amount: 10 }
|
||||
end
|
||||
|
||||
def test_belongs_to_with_touch_option_on_empty_update
|
||||
line_item = LineItem.create!
|
||||
Invoice.create!(line_items: [line_item])
|
||||
|
||||
assert_queries(0) { line_item.save }
|
||||
end
|
||||
|
||||
def test_belongs_to_with_touch_option_on_destroy
|
||||
line_item = LineItem.create!
|
||||
Invoice.create!(line_items: [line_item])
|
||||
|
|
Loading…
Reference in a new issue