Update model with array of IDs

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

On 21 February 2012 15:25, Rajarshi C. [email protected]
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?

Hey,
I get no error message.
It just doesn’t update any record.
Both the IDs are there in the DB table.

What’s more, even this does not work…
RSCampaign.update([1], {:end_date =>
Date.strptime(“120228”,"%y%m%d")})

though this works…
RSCampaign.update(1, {:end_date =>
Date.strptime(“120228”,"%y%m%d")})

Help please…

On 21.02.2012, at 19:25, Rajarshi C. 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)

On 21.02.2012, at 19:25, Rajarshi C. 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)

On 21.02.2012, at 23:42, Rajarshi C. wrote:

Thank you, Valery.
You are my hero.
Can you please post a link to the APIs?

api.rubyonrails.org

or

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”}]

Thank you, Valery.
You are my hero.
Can you please post a link to the APIs?