You might want to use active record's change tracking. if you had an
item, item.quantity_changed? tells you whether the quantity has
changed, item.quantity_change returns an array where the first item is
the old value, the second is the new value, item.changes is a hash of
attribute names to pairs like that returned by quantity_change.
Then if quantity has increased by 2, decrease Product.quantity by 2.
You could do this in a before_save or after_save - this would ensure
that is the save fails at some other point (e.g. the order fails some
separate validation) all of the changes get rolled back. You should
also be vary wary of race conditions - i'd look into using optimistic
locking on the products table.