ruby on rails - how to update_attributes with the conditions? -
I need to update the attributes but only for specific conditions such as rows
["
How do I do this?
It depends on whether you want to update a bulk SQL, or want to update on each model which also calls verification and normal callback series.
if You Want to translate and run the callback chain:
Model.find (: all, conditions => ["recipient_id =? And inbox_id =? And condition = 'unread'" , Current_user.id, @ inbox.id]) .org | obj | Obj.update_attributes (...) end
If you want to update SQL:
< Pre> Model.update_all ("attr1 = 'something', Attr2 = true, ...", ["recipient_id =? And inbox_id =? And condition = 'unread'", current_user.id, @inbox.id ])
Be sure to
Comments
Post a Comment