[Rails] Exchanging values of two records with unique-validated fields

2012-01-05 Thread Dmitry Suzdalev
Hi fellows! Is there a way to atomically exchange values of records which are validated using 'validates_uniqueness_of'? Some details follow. Imagine I have a model: class Item ActiveRecord::Base validates_uniqueness_of :weight end 'weight' is a sorting weight. I have an index.html view

Re: [Rails] Exchanging values of two records with unique-validated fields

2012-01-05 Thread Peter Vandenabeele
On Thu, Jan 5, 2012 at 2:35 PM, Dmitry Suzdalev dim...@gmail.com wrote: Hi fellows! Is there a way to atomically exchange values of records which are validated using 'validates_uniqueness_of'? Some details follow. Imagine I have a model: class Item ActiveRecord::Base

Re: [Rails] Exchanging values of two records with unique-validated fields

2012-01-05 Thread Dmitry Suzdalev
On 5 January 2012 18:09, Peter Vandenabeele pe...@vandenabeele.com wrote: If you mean atomic on the level of saving to the database (all or nothing), you would need a database transaction. http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html Second, to circumvent