blog.depold.com |
Web programming to the rescue! A blog about Node.JS, JavaScript and Ruby on Rails! |
stumblmumbl asked: Greetings! Not sure if this is the best place to ask, but I've got a sequelize question for you: is there a way to define something like a custom type, or perhaps add a constraint? For example, say I would like to add a column called "gender". I could make it a string, but then anything could be entered. I could make a "genders" table and do "Person.hasOne(Gender)", which is a common DB method, but kind of klunky since you would then have a "genderid" column. Is there a better way? Thanks!
Hi!
For now it is not possible to add a special data type. But you could use the boolean datatype for the ‘sex’-attribute and add a gender method which evaluates the attribute and returns ‘male’ or ‘female’ as value. Take a look at http://sequelizejs.com/?active=expanding-models#expanding-models and http://sequelizejs.com/?active=data-types#data-types for further information. What do you think?
With best regards,
Sascha