How can I specific type of column in knexJS?
I have the table Users:
id serial NOT NULL,
id_file_avatar bigint,
id_sectors bigint NOT NULL,
name character varying(50),
email character varying(100)
When I get in my rest I got it:
{
"user": {
"id": 1,
"id_file_avatar": null,
"id_sectors": "0",
"name": "Rodrigo Lopes",
"email": "[email protected]"
}
}
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 the id_sectors should be a int type, anyone knows why?
Thank you for helping me.
Are you sure you actually save
id_sectors
as integer?From the documentation:
Try using validator for your model, and set that
id_sectors
must be integer: https://github.com/fluxxu/bookshelf-validatorAdditionally, should this not work, you can always use
parseInt
to change your string value to integer.As for defining a model with attribute types, I don't think that's (currently) possible.