1
我需要在db中的许多记录的整数列加上一些值。 我试图做到这一点在 “干净” 的方式:加1到DB中的每个记录的整数记录
Transaction.where("account_id = ? AND date > ?", t.account_id, t.date).
update_all("account_state = account + ?", account_offset)
或
Transaction.where("account_id = ? AND date > ?", t.account_id, t.date).
update_all("account_state += ?", account_offset)
我得到错误:
QLite3::ConstraintException: constraint failed:
UPDATE "transactions" SET account_state = (account_state + ?)
WHERE (account_id = 1 AND date > '2012-03-01') AND (-10000)
但作品 “脏” 的方式:
Transaction.where("account_id = ? AND date > ?", t.account_id, t.date).
update_all("account_state = account + #{account_offset}")
有没有“干净”的方式来做t他?
谢谢你尝试,它的作品! – Alexey 2012-03-11 07:11:28