This project is archived and is in readonly mode.

#1769 ✓wontfix
Kieran P

Single row update without a select or knowing id

Reported by Kieran P | January 16th, 2009 @ 01:43 AM | in 2.x

I was looking for a single row update that doesn't use a select. The closest available in Rails in Model.update() but it required an ID, which I don't have. What I do have is the attributes of some of the other fields. I was hoping to use something like this for example:

Model.update({ :email => 'test@test.com' }, { :conditions => { :login => 'someone' })

The resulting SQL would look like this of course:

UPDATE model SET email = 'test@test.com' WHERE login = 'someone';

However, there doesn't seem to be a way to do this in Rails at the moment, and the only way to do it is to run a find_by_login and update_attribute call on the result, but as you know, that makes two queries.

Any ideas when a single update method that doesn't require an id, might be available?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages