I'm experimenting with bookshelf.js right now, and I created a sample table using the following knex migration:
exports.up = function(knex, Promise) {
return knex.schema.createTable( "users", function( table ) {
table.increments();
table.timestamps();
table.string( "email" );
} );
};
I then defined a bookshelf.js model:
var User = bookshelf.Model.extend( {
tableName: "users"
} );
and tried to save it:
var u = new User( { email: "[email protected]" } );
u.save();
Everything seems to work, and when I look at the database, the new user really was saved, however the timestamp-columns are NULL
. Also calling u.timestamp()
before calling u.save()
doesn't seem to have any effect.
What am I doing wrong here?
Ha, I finally got it!
You have to tell the model to use timestamps like this:
var User = bookshelf.Model.extend( {
tableName: "users",
hasTimestamps: true
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With