very simple question - I want to update one record only that matches 2 parameters.
Should I be doing it like this:
Model.where(:email =>"[email protected]",:code => "chejd").update(:password => "password").first
I have found examples using update_all but I only want to update a maximum of 1 record.
Check if this works with your DBMS and DB adapter:
Model.where(conditions).limit(1).update_all(changes) # => 1
Update:
The limit()
and update_all()
combo is an example in the docs, so it's probably supported by most DB adapters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With