Using the Postgres database, added a text field staff_ids
to branches
table:
add_column :branches, :staff_ids, :text
In controller added this field to branch_params list:
:staff_ids => []
Data has been saved in this column like ["","32","52"]
. When querying this field I got an error saying staff_ids should be an array
Branch.where("? = ANY(staff_ids)", '20')
ActiveRecord::StatementInvalid: PG::WrongObjectType: ERROR: op ANY/ALL (array) requires array on right side
Actually, I forgot to add array: true
option in the migration when adding staff_ids
field.
Now added another migration to change this column and tried to add array: true
option:
change_column :branches, :staff_ids, :text, array: true
But the migration failed with an error:
PG::DatatypeMismatch: ERROR: column "staff_ids" cannot be cast automatically to type text[]
Now either I want to update the where clause so that it filters the branches based on staff_ids without adding the array: true or fix the migration mentioned above.
Any suggestion / idea ?