admin管理员组文章数量:1219981
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?
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?
Share Improve this question asked Oct 4, 2014 at 20:15 DeX3DeX3 5,5497 gold badges46 silver badges70 bronze badges2 Answers
Reset to default 22Ha, I finally got it!
You have to tell the model to use timestamps like this:
var User = bookshelf.Model.extend( {
tableName: "users",
hasTimestamps: true
} );
example in typescript
import bookshelf from '../config/bookshelf';
class User extends bookshelf.Model<User> {
get tableName(): string {
return 'users';
}
get hasTimestamps(): boolean {
return true;
}
}
export default User;
本文标签: javascriptbookshelfjs timestamps not workingStack Overflow
版权声明:本文标题:javascript - bookshelf.js timestamps not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739334833a2158653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论