Reputation: 805
If I have something like:
Model1.update_all ['a1 = ?, a2 = ?', v1, v2], ['id = ?', id1]
Model2.update_all ['a3 = ?', v3], ['id = ?', id2]
How can I ensure that if one of the above updates fails that none of them has an effect, ie. a kind of rollback is performed?
Upvotes: 0
Views: 237
Reputation: 4461
This should do it..
Model1.transaction do
Model1.update_all ['a1 = ?, a2 = ?', v1, v2], ['id = ?', id1]
Model2.update_all ['a3 = ?', v3], ['id = ?', id2]
end
Upvotes: 2