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