sql - Beginner Rails Migration & Column Options in ActiveRecord -
quick question on :null option in activerecord table creation.
let's create new table column description.
def change create_table :products |t| t.string :name t.text :description, null: false end end if don't have :presence validation in model regarding description column, shouldn't "nothing" able passed description column? i'm not sure null: false can stop me passing nothing in since don't have validation in place.
rails migration or schema options null: false operate on database level (storage). if tried save record empty description field, receive database error (e.g. generated postgresql) wrapped in activerecord::statementinvalid:. on calling object.valid? object have been valid application point of view (rails).
rails validations :presence operate on application level. in case passing null value create object return false on valid? , access error messages object calling object.errors. if not bypassing validations, rails not allow save such record database.
Comments
Post a Comment