My project uses a lot of nested attributes in many forms, and those
model needed to be optimistically lock, using lock_version. When the
child model get updated or added the parent model has to be :touch.
Example would be the 'Invoice' and 'Invoice_items' scenario.
Any item added, changed or deleted form the Invoice_items the Invoice
has to be :touch(updated_at changed) and lock_version changed, in
order optimistically lock the record.
I have done this :-
class InvoiceItem < ActiveRecord::Base
belongs_to :invoice, :touch => true
end
class Invoice < ActiveRecord::Base
has_many :invoice_items
accept_nested_attributes :invoice_items, :allow_destroy => true
end
These resulted STALE error being raise.... because every invoice_item
that was change, It will :touch the invoice record once cause
lock_version to change.
I have try the http://github.com/UVSoft/touching_nested_attributes and
it solve the problem. Should ActiveRecord add
belongs_to :invoice, :silent_touch => true
as a new feature?
Thank You,