node.js - knexjs column specific type -
how can specific type of column in knexjs?
i have table users:
id serial not null, id_file_avatar bigint, id_sectors bigint not null, name character varying(50), email character varying(100) when in rest got it:
{ "user": { "id": 1, "id_file_avatar": null, "id_sectors": "0", "name": "rodrigo lopes", "email": "rodlps22@gmail.com" } } my usermodel
var user = bookshelf .model .extend({ tablename: 'users', visible: [ 'id', 'id_file_avatar', 'id_sectors', 'name', 'email' ], soft: false, initialize: function () { //this.on('saving', this.validatesave); }, validatesave: function () { return new checkit(rules).run(this.attributes); } }); but id_sectors should int type, knows why?
thank helping me.
are sure save id_sectors integer?
from documentation:
for example
new model({id: '1'}).load([relations...])not return samemodel({id: 1}).load([relations...])- notice id string in 1 case , number in other. can common mistake if retrieving id url parameter.
try using validator model, , set id_sectors must integer: https://github.com/fluxxu/bookshelf-validator
additionally, should not work, can use parseint change string value integer.
as defining model attribute types, don't think that's (currently) possible.
Comments
Post a Comment