【发布时间】:2013-12-12 13:50:42
【问题描述】:
使用带有 postgres 的 Rails 4.0.1 我有一个存储为数组的 activerecord 列
create_table "accounts", force: true do |t|
t.string "schedule_days", default: [], array: true
end
我可以分配一个数组就好了。
agent.schedule_days = agent.schedule_days << 1
=> [1]
但保存不会持续。
agent = Account.last
agent.save
BEGIN
COMMIT
一些论坛建议 ActiveRecord 需要将列弄脏,所以:
agent.schedule_days_will_change!
=> [1]
这会导致 SQL 语句发生更改,但会引发 ArgumentError。
agent.save
(0.3ms) BEGIN
SQL (0.9ms) UPDATE "accounts" SET "schedule_days" = $1, "updated_at" = $2
WHERE "accounts"."type" IN ('Ghost') AND "accounts"."id" = 6543
[["schedule_days", [1]], ["updated_at", Wed, 27 Nov 2013 03:56:14 UTC +00:00]]
ArgumentError: wrong number of arguments (3 for 2): UPDATE "accounts" SET "schedule_days" = $1, "updated_at" = $2 WHERE "accounts"."type" IN ('Ghost') AND "accounts"."id" = 6543
(0.3ms) ROLLBACK
ArgumentError: wrong number of arguments (3 for 2)
【问题讨论】:
-
原来是一个过时的 activerecord 适配器导致了这个问题。
标签: arrays postgresql activerecord ruby-on-rails-4