Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
share|improve this question
    
Turns out it was an outdated activerecord adapter causing the problem. –  Darren Nix Nov 27 '13 at 6:41

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
Brilliant! Updated from 0.6.3 to 0.6.5 and it works. –  Darren Nix Nov 27 '13 at 6:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.