新しいレコードを作成するときに、 Bookshelf.jsで電子メールが既に存在することを検証しようとしています。
ここgithubで1つの解決策を見つけましたが、 Promiseで試しても機能しません
User = bookshelf.Model.extend({
tableName: 'users',
initialize: function() {
this.on('saving', this._assertEmailUnique);
},
_assertEmailUnique: function(model, attributes, options) {
if (this.hasChanged('email')) {
return this
.query('where', 'email', this.get('email'))
.fetch(_.pick(options, 'transacting'))
.then(function (existing) {
if (!existing) throw new Error('duplicate email');
});
}
}
});
モデルの検証では、現在Joiを使用していますが、 Joi もこのカスタム検証をサポートしていないようです。Postgres データベースを使用しています。それを行う他の方法があります..助けてください...
前もって感謝します..