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

You need to sign in or sign up before continuing.
Commit e6ad737e by Sorin Neacsu

BelongsToMany.injectAttributes: replace model.init call with model.refreshAttributes

1 parent 892619e4
......@@ -376,7 +376,7 @@ BelongsToMany.prototype.injectAttributes = function() {
this.paired.foreignIdentifierField = this.through.model.rawAttributes[this.paired.otherKey].field || this.paired.otherKey;
}
this.through.model.init(this.through.model.modelManager);
this.through.model.refreshAttributes();
this.toSource = new BelongsTo(this.through.model, this.source, {
foreignKey: this.foreignKey
......
......@@ -370,6 +370,28 @@ describe(Support.getTestDialectTeaser('belongsToMany'), function() {
});
});
describe('associations on the join table', function () {
beforeEach(function() {
this.User = this.sequelize.define('User', {});
this.Project = this.sequelize.define('Project', {});
this.UserProjects = this.sequelize.define('UserProjects', {});
this.UserProjects.belongsTo(this.User);
this.User.belongsToMany(this.Project, { through: this.UserProjects });
this.Project.belongsToMany(this.User, { through: this.UserProjects });
this.UserProjects.belongsTo(this.Project);
});
it('should work for belongsTo associations defined before belongsToMany', function () {
expect(this.UserProjects.Instance.prototype.getUser).to.be.ok;
});
it('should work for belongsTo associations defined after belongsToMany', function () {
expect(this.UserProjects.Instance.prototype.getProject).to.be.ok;
});
});
describe('self-associations', function () {
it('does not pair multiple self associations with different through arguments', function () {
var User = current.define('user', {})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!