2

I know this question may sound duplicated, but none of the solutions I've found actually solved my problem.

I have a model named pet with photos column, here's my schema:

t.string "photos", default: [], array: true

I'm not using the serialize method in my class because a lot of other sources confirmed that it's not necessary.

Here's my object:

#<Pet id: 9, name: nil, age: nil, vaccinated: nil, male: nil, pet_description: nil, additional_info: nil, size: nil, neutered: nil, classified_id: nil, created_at: "2016-10-21 23:36:37", updated_at: "2016-10-21 23:55:50", kind: nil, photos: []>

No matter I do, I cannot persist a new photo array:

UPDATE "pets" SET "updated_at" = $1, "photos" = $2 WHERE "pets"."id" = $3  [["updated_at", 2016-10-21 23:51:30 UTC], ["photos", "{}"], ["id", 9]]

I've already tried several ways of persisting, like:

model.array << element
model.array_will_change!
model.save!  

or even (like this guy suggested, and this other guy as well):

update_attributes locations: locations + [ place ]

and none of them seems to work.

Using Postgres command line I was able to save and update and array with no problems, but this issue seems to be related to active record.

activerecord (5.0.0.1) postgres (9.6.0.0)

Thanks a lot :-)

1
  • What is the result when you do model.photos << 'test'; model.save Commented Oct 22, 2016 at 8:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.