Using Rails 4.0.1 with postgres I have an activerecord column stored as an array
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:
agent.schedule_days_will_change!
=> [1]
This causes the SQL statement to change but it raises an 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. There may be an updated version of the activerecord-postgis-adapter
that supports arrays.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.