ruby on rails - Should I use integer or string to declare this attribute? -
i'm building app ruby on rails mesure demographic variables. right now, have doubt how declare type of data 2 attributes of model (stats) belongs users model. attributes "genere" , "civil status". know elements string data if pretend make statistics info, would more convenient declare data integer?, say, nominative data in statistic number enough represent status or genere, ie. 1 -> femenin / 2 -> masculin.
i'll appreciate advice. time.
enums integer bitmasks way attributes there definite amount of choices , add/removing options developer level concern.
class person < applicationrecord enum gender: [:undisclosed, :male, :female, :other] end
this store gender in integer column values 0-3. column faster scan , index string column.
it saves hassle of whitelisting acceptable string values , writing scopes based on value.
you can person.female
scope.
Comments
Post a Comment