ActiveRecord can do conditonal update?

ActiveRecord update method can support condition (SQL where clause)?

My rails application always query data by some unique key then update
this data (if no data, create one). It is two SQL statement. Want to
improve the performance, combine it into one SQL update statement.

if ActiveRecord not support, can i have some way to customize
ActiveRecord ?

Thanks a lot
–Jian

ActiveRecord update method can support condition (SQL where clause)?

My rails application always query data by some unique key
then update this data (if no data, create one). It is two SQL
statement. Want to improve the performance, combine it into
one SQL update statement.

if ActiveRecord not support, can i have some way to customize
ActiveRecord ?

http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000999

you’ll need to check the update count to see if the object doesn’t
already exist, of course.

  • donald