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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -