My migration file contains:
t.belongs_to :user, index: true
t.belongs_to :organization, index: true
t.boolean :member, default: false, null: false
t.boolean :admin, default: false, null: false
t.boolean :moderator, default: false, null: false
The model file includes:
validates :member, presence: true
validates :admin, presence: true
validates :moderator, presence: true
In my seeds file I create
a new record:
user.relationships.create!(organization_id: 2, member: true, moderator: true)
This fails with the error Admin can't be blank
and indeed if I add admin: false
to the seeds line, the error is gone. But I would expect that when I don't specify the value for admin
, it would take on its default value from the migration file. Why is its behaviour different from my expectation? Am I doing something wrong or is my expectation incorrect so that I always need to specify values for variables that are not allowed to be nil?