how to update a record without worrying about primary key
Posted
by railsnew
on Stack Overflow
See other posts from Stack Overflow
or by railsnew
Published on 2010-04-26T02:47:15Z
Indexed on
2010/04/26
2:53 UTC
Read the original article
Hit count: 530
In ActiveRecord how can we update a record without worrying/knowing primary key.
If I do
Address.update(15, :user_name => 'Samuel')
it corresponds to
UPDATE addresses set user_name = 'Samuel' where id = 15
but what if i want to do:
UPDATE addresses set user_name = 'Samuel' where cid = 15
what will be the ActiveRecord equivalent of that??
I tried:
Address.update({:cid => 15}, :user_name => 'Samuel')
but that does not work.
© Stack Overflow or respective owner