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

Commit 061787f9 by Pedro Augusto de Paula Barbosa Committed by Sushant

fix(scope): conform includes correctly (#10691)

1 parent 0f505eff
......@@ -1554,6 +1554,7 @@ class Model {
}
if (scope) {
this._conformIncludes(scope, this);
this._assignOptions(self._scope, scope);
self._scopeNames.push(scopeName ? scopeName : 'defaultScope');
} else {
......
......@@ -9,6 +9,45 @@ const chai = require('chai'),
describe(Support.getTestDialectTeaser('Model'), () => {
describe('scope', () => {
describe('simple merge', () => {
beforeEach(function() {
this.Foo = this.sequelize.define('foo', { name: Sequelize.STRING }, { timestamps: false });
this.Bar = this.sequelize.define('bar', { name: Sequelize.STRING }, { timestamps: false });
this.Baz = this.sequelize.define('baz', { name: Sequelize.STRING }, { timestamps: false });
this.Foo.belongsTo(this.Baz, { foreignKey: 'bazId' });
this.Foo.hasOne(this.Bar, { foreignKey: 'fooId' });
this.createEntries = () => {
return this.Baz.create({ name: 'The Baz' })
.then(baz => this.Foo.create({ name: 'The Foo', bazId: baz.id }))
.then(foo => this.Bar.create({ name: 'The Bar', fooId: foo.id }));
};
this.scopes = {
includeBar: { include: this.Bar },
includeBaz: { include: this.Baz }
};
this.Foo.addScope('includeBar', this.scopes.includeBar);
this.Foo.addScope('includeBaz', this.scopes.includeBaz);
return this.sequelize.sync({ force: true }).then(this.createEntries);
});
it('should merge simple scopes correctly', function() {
return this.Foo.scope('includeBar', 'includeBaz').findOne().then(result => {
const json = result.toJSON();
expect(json.bar).to.be.ok;
expect(json.baz).to.be.ok;
expect(json.bar.name).to.equal('The Bar');
expect(json.baz.name).to.equal('The Baz');
});
});
});
describe('complex merge', () => {
beforeEach(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!