Skip to content

Commit

Permalink
Merge pull request #14390 from huoxito/true-touch
Browse files Browse the repository at this point in the history
Still touch associations when theres no timestamp
  • Loading branch information
rafaelfranca committed Mar 25, 2014
1 parent 31f6f01 commit 2400e44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -450,6 +450,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

Expand Down
Expand Up @@ -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])
Expand Down

0 comments on commit 2400e44

Please sign in to comment.