Permalink
Browse files

Still touch associations when theres no timestamp

Prior to Rails 4.0.4 when touching a object which doesn't have timestamp
attributes (updated_at / updated_on) rails would still touch all
associations. After 73ba2c1 it updates
associations but rollsback because `touch` would return nil since
there's no timestamp attribute
  • Loading branch information...
1 parent b4c9649 commit ea3a73e720b5ffed6b6220dc9ce92776804cb06f @huoxito huoxito committed Mar 15, 2014
View
2 activerecord/lib/active_record/persistence.rb
@@ -452,6 +452,8 @@ def touch(name = nil)
changed_attributes.except!(*changes.keys)
primary_key = self.class.primary_key
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
+ else
+ true
end
end
View
11 activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -340,6 +340,17 @@ def test_belongs_to_with_touch_option_on_touch
assert_queries(1) { line_item.touch }
end
+ def test_belongs_to_with_touch_option_on_touch_without_updated_at_attributes
+ assert !LineItem.column_names.include?("updated_at")
+
+ line_item = LineItem.create!
+ invoice = Invoice.create!(line_items: [line_item])
+ initial = invoice.updated_at
+ line_item.touch
+
+ refute_equal initial, invoice.reload.updated_at
+ end
+
def test_belongs_to_with_touch_option_on_touch_and_removed_parent
line_item = LineItem.create!
Invoice.create!(line_items: [line_item])

0 comments on commit ea3a73e

Please sign in to comment.