I'm referring to this blog on how to use postgresql arrays in Rails 4. To be more precise, I'm using Rails 4.1.8.
I would like to enforce that the array should not be empty(should have at least one or more values) wrt the below table definition for the phones attribute.
Setting null: false as done below prevents me from doing a Contacts.create(phones: nil), but Contacts.create(phones: []) saves to the database.
class CreateContacts < ActiveRecord::Migration
def change
create_table :contacts do |t|
t.string :name
t.text :phones, array: true, null: false
end
end
end
What constraint can I use to ensure that Contacts.create(phones: []) raises an error saying that there should be at least one entry within the array?
phonesis empty or just an ActiveRecord validation?