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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ball, Donald A Jr (Library)
2007-Jul-27 21:15 UTC
Re: 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 ?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---