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@googlegroups.com.
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.

Search Discussions

  • Michael Pavling at Feb 21, 2012 at 3:32 pm

    On 21 February 2012 15:25, Rajarshi Chakravarty 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@googlegroups.com.
    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.
  • Rajarshi Chakravarty at Feb 21, 2012 at 5:30 pm
    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@googlegroups.com.
    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.
  • Valery Kvon at Feb 21, 2012 at 7:00 pm

    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@googlegroups.com.
    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.
  • Valery Kvon at Feb 21, 2012 at 7:03 pm

    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@googlegroups.com.
    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.
  • Rajarshi Chakravarty at Feb 21, 2012 at 7:42 pm
    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@googlegroups.com.
    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.
  • Valery Kvon at Feb 21, 2012 at 8:00 pm

    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 21, '12 at 3:25p
activeFeb 21, '12 at 8:00p
posts7
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase