Rails: Should I set default column value at the database level, or in the model? -
i'm adding multiplier column 1 of models, , should have default value of 1. i'm wondering if it's preferable add default value @ database layer or in callback in model. i'm leaning toward model in name of database agnosticity (if that's word, guess it's not). right so?
since can declare default in rails migration , migrations use database adapters, setting default in migration sufficiently database agnostic purposes. e.g.:
class addmultipliercolumn < activerecord::migration def change add_column :my_table, :multiplier, :float, default: 1.0 end end
Comments
Post a Comment