不要怂,就是干,撸起袖子干!

Commit b634cd87 by Takashi Sasaki Committed by Sushant

fix(model): validate virtual attribute (#9947) (#10085)

1 parent 122bd174
...@@ -2500,7 +2500,7 @@ class Model { ...@@ -2500,7 +2500,7 @@ class Model {
ignoreDuplicates: false ignoreDuplicates: false
}, options); }, options);
options.fields = options.fields || Object.keys(this.tableAttributes); options.fields = options.fields || Object.keys(this.rawAttributes);
const dialect = this.sequelize.options.dialect; const dialect = this.sequelize.options.dialect;
......
...@@ -689,5 +689,51 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -689,5 +689,51 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}); });
}); });
describe('virtual attribute', () => {
beforeEach(function() {
this.User = this.sequelize.define('user', {
password: {
type: Sequelize.VIRTUAL,
validate: {
customValidator: () => {
throw new Error('always invalid');
}
}
}
});
});
it('sholud validate', function() {
return this.User
.sync({ force: true })
.then(() => this.User.bulkCreate([
{ password: 'password' }
], { validate: true }))
.then(() => {
expect.fail();
}, error => {
expect(error.length).to.equal(1);
expect(error[0].message).to.match(/.*always invalid.*/);
});
});
it('shold not validate', function() {
return this.User
.sync({ force: true })
.then(() => this.User.bulkCreate([
{ password: 'password' }
], { validate: false }))
.then(users => {
expect(users.length).to.equal(1);
})
.then(() => this.User.bulkCreate([
{ password: 'password' }
]))
.then(users => {
expect(users.length).to.equal(1);
});
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!