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

Commit e33d2bdc by Sushant Committed by GitHub

fix(reload): include default scope (#12399)

1 parent 5611ef0b
...@@ -4043,7 +4043,7 @@ class Model { ...@@ -4043,7 +4043,7 @@ class Model {
options = Utils.defaults({ options = Utils.defaults({
where: this.where() where: this.where()
}, options, { }, options, {
include: this._options.include || null include: this._options.include || undefined
}); });
const reloaded = await this.constructor.findOne(options); const reloaded = await this.constructor.findOne(options);
......
...@@ -301,5 +301,36 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -301,5 +301,36 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
const leTeam = await leTeam0.reload(); const leTeam = await leTeam0.reload();
expect(leTeam.Players).to.have.length(1); expect(leTeam.Players).to.have.length(1);
}); });
it('should inject default scope when reloading', async function() {
const Bar = this.sequelize.define('Bar', {
name: DataTypes.TEXT
});
const Foo = this.sequelize.define('Foo', {
name: DataTypes.TEXT
}, {
defaultScope: {
include: [{ model: Bar }]
}
});
Bar.belongsTo(Foo);
Foo.hasMany(Bar);
await this.sequelize.sync();
const foo = await Foo.create({ name: 'foo' });
await foo.createBar({ name: 'bar' });
const fooFromFind = await Foo.findByPk(foo.id);
expect(fooFromFind.Bars).to.be.ok;
expect(fooFromFind.Bars[0].name).to.equal('bar');
await foo.reload();
expect(foo.Bars).to.be.ok;
expect(foo.Bars[0].name).to.equal('bar');
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!