Folks, I display a set of records to the user who can make changes to one or more of those records. When the user saves the changes, I get them back in an array that contains only the changed records - with both the modified an unmodified attributes for each record. This array also has the unique id for each record. What is the best/fastest way for me to update the records in the db? Or do I just have to iterate through the array, retrieving each record again from the db and setting up the call to update_attributes by retrieving each attribute individually from the array? It feels so unlike rails to have to do that and sounds like there must be a more efficient way to get all the changed data from the array to the database perhaps in a single call. Appreciate any pointers or help. I am using Rails 2.2 if that is a factor in your answer. Thanks, -S -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Mar-11 09:58 UTC
Re: Can you update a db record without first retrieving it?
On Mar 11, 3:14 am, Sj Tib <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> What is the best/fastest way for me to update the records in the db? Or > do I just have to iterate through the array, retrieving each record > again from the db and setting up the call to update_attributes by > retrieving each attribute individually from the array?Have a look at the update_all method in the api docs. Fred> > It feels so unlike rails to have to do that and sounds like there must > be a more efficient way to get all the changed data from the array to > the database perhaps in a single call. > > Appreciate any pointers or help. I am using Rails 2.2 if that is a > factor in your answer. > > Thanks, > -S > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---