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

Commit a54a7a5e by Claire L Committed by Sushant

fix(model/findOrBuild): handle includes (#8938)

1 parent d65a95c9
......@@ -2058,7 +2058,7 @@ class Model {
values = Utils.defaults(values, options.where);
}
instance = this.build(values);
instance = this.build(values, options);
return Promise.resolve([instance, true]);
}
......
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../support'),
DataTypes = require(__dirname + '/../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), () => {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
age: DataTypes.INTEGER
});
this.Project = this.sequelize.define('Project', {
name: DataTypes.STRING
});
this.User.hasMany(this.Project);
this.Project.belongsTo(this.User);
return this.sequelize.sync({force: true});
});
describe('findOrBuild', () => {
it('initialize with includes', function() {
return this.User.bulkCreate([
{ username: 'Mello', age: 10 },
{ username: 'Mello', age: 20 }
], { returning: true }).spread((user1, user2) => {
return this.Project.create({
name: 'Investigate'
}).then(project => user2.setProjects([project]));
}).then(() => {
return this.User.findOrBuild({
defaults: {
username: 'Mello',
age: 10
},
where: {
age: 20
},
include: [{
model: this.Project
}]
});
}).spread((user, created) => {
expect(created).to.be.false;
expect(user.get('id')).to.be.ok;
expect(user.get('username')).to.equal('Mello');
expect(user.get('age')).to.equal(20);
expect(user.Projects).to.have.length(1);
expect(user.Projects[0].get('name')).to.equal('Investigate');
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!