But I keep getting an error during the INSERT, saying column
category_ids is of type ‘integer[]’ but expression is of type ‘integer’.
In the generate SQL, the value for category_ids is always 1, no matter
what values I have placed in the array.
Maybe I need to simplify the problem/question. I have a table with a
column which holds an array of integers. Rails treats the column as an
integer column, which fails when trying to insert data, as the arrays I
assign to the record object seem to have .to_i called on the array as a
whole, resulting in a 1 or a 0.
How can I insert data in an array column? Is there a way to tell rails
that column x is of type integer[]? I know both mySQL and Postgres both
have array columns, so someone must have come across this before, yet I
can’t find anything on google.
I am at work now, tonight I will give your suggestion a try:
So I should try changing the recipe model to has_and_belongs_to_many,
and the insertion should work?
Near as I can tell, MySQL does not support integer arrays. If you
really want to save an array in a column, then you should probably
serialize it.
take a look for ‘serialize’ in the Rails API.
_Kevin
I can’t remember where I read that it does, but I did turn up this, OSCON Day #2: New Features in MySQL (by Jeremy Zawodny)
Though I can’t seem to turn up anything in the official release notes.
So now I am unsure.