I have an issue where I am trying to update multiple models of the same type in a post. The first model in the loop gets updated but the rest don't for some reason.
I've posted the ser开发者_Go百科ver log where you can see it finding and updating the first model and then just finding the rest.
Does anyone have any ideas as to what my issue is here? Thanks
def special_save
temp = params["_json"]
temp.each { |h|
hh = h['h_w']
h_w = HourWorking.find(hh[:id])
hh.delete('id')
h_w.update_attributes(hh)
}
end
HourWorking Load (2.5ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 187) LIMIT 1
SQL (1.2ms) BEGIN
SQL (3.7ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"hour_workings"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
SQL (1.7ms) UPDATE "hour_workings" SET "end_time" = '2000-01-01 04:45:00.000000', "start_time" = '2000-01-01 01:45:00.000000', "updated_at" = '2011-02-10 10:18:19.955198' WHERE ("hour_workings"."id" = 187)
SQL (4.3ms) COMMIT
HourWorking Load (1.7ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 169) LIMIT 1
SQL (1.2ms) BEGIN
SQL (12.8ms) COMMIT
HourWorking Load (6.0ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 154) LIMIT 1
SQL (1.5ms) BEGIN
SQL (1.3ms) COMMIT
HourWorking Load (2.3ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 170) LIMIT 1
SQL (9.8ms) BEGIN
SQL (1.1ms) COMMIT
HourWorking Load (1.5ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 171) LIMIT 1
SQL (1.2ms) BEGIN
SQL (12.3ms) COMMIT
HourWorking Load (6.2ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 165) LIMIT 1
SQL (1.1ms) BEGIN
SQL (1.6ms) COMMIT
HourWorking Load (2.0ms) SELECT "hour_workings".* FROM "hour_workings" WHERE ("hour_workings"."id" = 153) LIMIT 1
SQL (1.0ms) BEGIN
SQL (1.6ms) COMMIT
try to delete the :id key
hh.delete(:id)
Ah I have found my problem.
I had an issue where the params that I was posting were exact copies of what was already in the database.
精彩评论