【发布时间】:2015-07-25 07:23:05
【问题描述】:
我有一个表设置有时间戳和书架配置为使用它们。通常一切都会按原样发生,而 bookshelf 会处理时间戳,但我有一个案例我想指定它们,但是当我尝试这样做时,这些值将被忽略并使用当前日期。
我已尝试将我的用例简化为基本要素:
var Author = Bookshelf.Model.extend({
tableName: 'authors',
hasTimestamps: ['created_at', 'updated_at'],
bookAuthors: function(){
return this.hasMany(require('.book_authors'));
},
associateBookWithAuthor(bookId,timestamp) {
return self.related('bookAuthors').create({
book_id: bookId,
updated_at: timestamp, // ignored by bookshelf
created_at: timestamp // also ignored
})
}
}
我仍然希望为常规用例配置 hasTimestamps。是否可以让 Bookshelf 让我覆盖时间戳行为?
【问题讨论】:
标签: javascript node.js bookshelf.js knex.js