[英]Saving array to postgres in Rails raises ArgumentError: wrong number of arguments (3 for 2)
Using Rails 4.0.1 with postgres I have an activerecord column stored as an array 将Rails 4.0.1与postgres一起使用时,我有一个activerecord列存储为数组
create_table "accounts", force: true do |t|
t.string "schedule_days", default: [], array: true
end
I can assign an array just fine. 我可以分配一个数组就好了。
agent.schedule_days = agent.schedule_days << 1
=> [1]
But the save does not persist. 但是保存不会持久。
agent = Account.last
agent.save
BEGIN
COMMIT
Some of the forums suggested that the ActiveRecord needs the column to be dirtied so: 一些论坛建议ActiveRecord需要将该列弄脏,以便:
agent.schedule_days_will_change!
=> [1]
This causes the SQL statement to change but it raises an ArgumentError. 这会导致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)
This is because the activerecord-postgis-adapter
is begin used rather than the default postgresql
adapter provided by Rails. 这是因为开始使用
activerecord-postgis-adapter
而不是Rails提供的默认postgresql
适配器。 There may be an updated version of the activerecord-postgis-adapter
that supports arrays. 可能存在支持数组的
activerecord-postgis-adapter
的更新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.