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

Commit 07fe591e by Peter Müller Committed by Sushant

fix(belongs-to): create now returns target model (#9980)

1 parent 053145cd
......@@ -221,15 +221,15 @@ class BelongsTo extends Association {
*
* @see {@link Model#create} for a full explanation of options
*
* @returns {Promise}
* @returns {Promise<Model>} The created target model
*/
create(sourceInstance, values, options) {
values = values || {};
options = options || {};
return this.target.create(values, options)
.then(newAssociatedObject =>
sourceInstance[this.accessors.set](newAssociatedObject, options)
.then(newAssociatedObject => sourceInstance[this.accessors.set](newAssociatedObject, options)
.then(() => newAssociatedObject)
);
}
}
......
......@@ -239,7 +239,7 @@ class HasOne extends Association {
*
* @see {@link Model#create} for a full explanation of options
*
* @returns {Promise}
* @returns {Promise<Model>} The created target model
*/
create(sourceInstance, values, options) {
values = values || {};
......
......@@ -412,11 +412,9 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
return this.sequelize.sync({ force: true }).then(() => {
return Task.create({ title: 'task' }).then(task => {
return task.createUser({ username: 'bob' }).then(() => {
return task.getUser().then(user => {
expect(user).not.to.be.null;
expect(user.username).to.equal('bob');
});
return task.createUser({ username: 'bob' }).then(user => {
expect(user).not.to.be.null;
expect(user.username).to.equal('bob');
});
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!