Hi, I am trying to use the update method of activerecord with an array of ids as the first param. It does not update any row. The APIs say that it should work. The array contains 2 IDs. RSCampaign.update([1,2], {:end_date => Date.strptime("120228","%y%m%d")}) If I put an ID instead of the array, it updates fine. Please help. I am using ruby 1.8.6 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 February 2012 15:25, Rajarshi Chakravarty <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am trying to use the update method of activerecord with an array of > ids as the first param. > It does not update any row. The APIs say that it should work.What error message do you get? Do both of those IDs map to records? Do either of them get updated? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey, I get no error message. It just doesn''t update any record. Both the IDs are there in the DB table. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21.02.2012, at 19:25, Rajarshi Chakravarty wrote:> Hi, > I am trying to use the update method of activerecord with an array of > ids as the first param. > It does not update any row. The APIs say that it should work. > > The array contains 2 IDs. > RSCampaign.update([1,2], {:end_date => > Date.strptime("120228","%y%m%d")}) > > If I put an ID instead of the array, it updates fine.API says that exactly: RSCampaign.update([1,2], {:end_date =>[Date.strptime("120228","%y%m%d")}]*2) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21.02.2012, at 19:25, Rajarshi Chakravarty wrote:> Hi, > I am trying to use the update method of activerecord with an array of > ids as the first param. > It does not update any row. The APIs say that it should work. > > The array contains 2 IDs. > RSCampaign.update([1,2], {:end_date => > Date.strptime("120228","%y%m%d")})sorry RSCampaign.update([1,2], [{:end_date =>Date.strptime("120228","%y%m%d")}]*2) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you, Valery. You are my hero. Can you please post a link to the APIs? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21.02.2012, at 23:42, Rajarshi Chakravarty wrote:> Thank you, Valery. > You are my hero. > Can you please post a link to the APIs?api.rubyonrails.org or https://github.com/rails/rails/blob/d22592a05b299c21e30ec8b38890a178dca863b4/activerecord/lib/active_record/relation.rb#L312 people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } } Person.update(people.keys, people.values) people is a Hash people.keys is an Array of keys # [1,2] people.values is an Array of values # [{ "first_name" => "David" }, { "first_name" => "Jeremy"}] -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.