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

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