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

Commit 7c716215 by Mick Hansen

chore(associations/scope): fix a few failing tests

1 parent 2e031545
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#### Backwards compatability changes #### Backwards compatability changes
- The `fieldName` property, used in associations with a foreign key object `(A.hasMany(B, { foreignKey: { ... }})`, has been renamed to `name` to avoid confusion with `field`. - The `fieldName` property, used in associations with a foreign key object `(A.hasMany(B, { foreignKey: { ... }})`, has been renamed to `name` to avoid confusion with `field`.
- The naming of the join table entry for N:M association getters is now singular (like includes)
# v2.0.0-dev13 # v2.0.0-dev13
We are working our way to the first 2.0.0 release candidate. We are working our way to the first 2.0.0 release candidate.
......
...@@ -44,10 +44,11 @@ module.exports = (function() { ...@@ -44,10 +44,11 @@ module.exports = (function() {
options.include.push({ options.include.push({
model: through.model, model: through.model,
as: Utils.singularize(through.model.tableName), as: Utils.singularize(through.model.tableName),
attributes: options.joinTableAttributes,
association: { association: {
isSingleAssociation: true, isSingleAssociation: true,
source: self.association.source, source: self.association.target,
target: self.association.target, target: self.association.source,
identifier: self.association.foreignIdentifier identifier: self.association.foreignIdentifier
}, },
required: true, required: true,
......
...@@ -136,7 +136,7 @@ module.exports = (function() { ...@@ -136,7 +136,7 @@ module.exports = (function() {
})); }));
if (this.targetAssociation) { if (this.targetAssociation) {
this.targetAssociation.through = this.through; this.targetAssociation.through.model = this.through.model;
} }
} }
......
...@@ -1800,7 +1800,7 @@ module.exports = (function() { ...@@ -1800,7 +1800,7 @@ module.exports = (function() {
tableNames[include.model.getTableName()] = true; tableNames[include.model.getTableName()] = true;
if (include.hasOwnProperty('attributes')) { if (include.attributes) {
include.originalAttributes = include.attributes.slice(0); include.originalAttributes = include.attributes.slice(0);
include.model.primaryKeyAttributes.forEach(function(attr) { include.model.primaryKeyAttributes.forEach(function(attr) {
if (include.attributes.indexOf(attr) === -1) { if (include.attributes.indexOf(attr) === -1) {
......
...@@ -894,9 +894,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -894,9 +894,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}).then(function(projects) { }).then(function(projects) {
expect(projects).to.have.length(1); expect(projects).to.have.length(1);
var project = projects[0]; var project = projects[0];
expect(project.ProjectUsers).to.be.defined; expect(project.ProjectUser).to.be.defined;
expect(project.status).not.to.exist; expect(project.status).not.to.exist;
expect(project.ProjectUsers.status).to.equal('active'); expect(project.ProjectUser.status).to.equal('active');
}); });
}); });
}); });
...@@ -1366,7 +1366,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1366,7 +1366,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(associationName).not.to.equal(this.User.tableName); expect(associationName).not.to.equal(this.User.tableName);
expect(associationName).not.to.equal(this.Task.tableName); expect(associationName).not.to.equal(this.Task.tableName);
var through = this.User.associations[associationName].through; var through = this.User.associations[associationName].through.model;
if (typeof through !== 'undefined') { if (typeof through !== 'undefined') {
expect(through.tableName).to.equal(associationName); expect(through.tableName).to.equal(associationName);
} }
...@@ -1393,7 +1393,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1393,7 +1393,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(ParanoidTask.options.paranoid).to.be.ok; expect(ParanoidTask.options.paranoid).to.be.ok;
_.forEach(ParanoidUser.associations, function (association) { _.forEach(ParanoidUser.associations, function (association) {
expect(association.through.options.paranoid).not.to.be.ok; expect(association.through.model.options.paranoid).not.to.be.ok;
}); });
}); });
}); });
...@@ -1475,7 +1475,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1475,7 +1475,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
_.each([this.UserTasks, this.UserTasks2], function (model) { _.each([this.UserTasks, this.UserTasks2], function (model) {
fk = Object.keys(model.options.uniqueKeys)[0]; fk = Object.keys(model.options.uniqueKeys)[0];
expect(model.options.uniqueKeys[fk].fields).to.deep.equal([ 'TaskId', 'UserId' ]); expect(model.options.uniqueKeys[fk].fields.sort()).to.deep.equal([ 'TaskId', 'UserId' ]);
}); });
}); });
...@@ -1541,8 +1541,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1541,8 +1541,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(project.UserProjects).to.be.defined; expect(project.UserProjects).to.be.defined;
expect(project.status).not.to.exist; expect(project.status).not.to.exist;
expect(project.UserProjects.status).to.equal('active'); expect(project.UserProject.status).to.equal('active');
expect(project.UserProjects.data).to.equal(42); expect(project.UserProject.data).to.equal(42);
}); });
}); });
...@@ -1559,8 +1559,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1559,8 +1559,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(project.UserProjects).to.be.defined; expect(project.UserProjects).to.be.defined;
expect(project.status).not.to.exist; expect(project.status).not.to.exist;
expect(project.UserProjects.status).to.equal('active'); expect(project.UserProject.status).to.equal('active');
expect(project.UserProjects.data).not.to.exist; expect(project.UserProject.data).not.to.exist;
}); });
}); });
}); });
...@@ -1844,9 +1844,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1844,9 +1844,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
User.hasMany(Group, { as: 'MyGroups', through: 'group_user'}); User.hasMany(Group, { as: 'MyGroups', through: 'group_user'});
Group.hasMany(User, { as: 'MyUsers', through: 'group_user'}); Group.hasMany(User, { as: 'MyUsers', through: 'group_user'});
expect(Group.associations.MyUsers.through === User.associations.MyGroups.through); expect(Group.associations.MyUsers.through.model === User.associations.MyGroups.through.model);
expect(Group.associations.MyUsers.through.rawAttributes.UserId).to.exist; expect(Group.associations.MyUsers.through.model.rawAttributes.UserId).to.exist;
expect(Group.associations.MyUsers.through.rawAttributes.GroupId).to.exist; expect(Group.associations.MyUsers.through.model.rawAttributes.GroupId).to.exist;
}); });
it("correctly identifies its counterpart when through is a model", function () { it("correctly identifies its counterpart when through is a model", function () {
...@@ -1857,10 +1857,10 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1857,10 +1857,10 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
User.hasMany(Group, { as: 'MyGroups', through: UserGroup}); User.hasMany(Group, { as: 'MyGroups', through: UserGroup});
Group.hasMany(User, { as: 'MyUsers', through: UserGroup}); Group.hasMany(User, { as: 'MyUsers', through: UserGroup});
expect(Group.associations.MyUsers.through === User.associations.MyGroups.through); expect(Group.associations.MyUsers.through.model === User.associations.MyGroups.through.model);
expect(Group.associations.MyUsers.through.rawAttributes.UserId).to.exist; expect(Group.associations.MyUsers.through.model.rawAttributes.UserId).to.exist;
expect(Group.associations.MyUsers.through.rawAttributes.GroupId).to.exist; expect(Group.associations.MyUsers.through.model.rawAttributes.GroupId).to.exist;
}); });
}); });
}); });
...@@ -2234,15 +2234,15 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -2234,15 +2234,15 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(Task.rawAttributes.uid).not.to.be.defined; expect(Task.rawAttributes.uid).not.to.be.defined;
expect(Task.associations.tasksusers.through.rawAttributes.taskId).to.be.defined; expect(Task.associations.tasksusers.through.model.rawAttributes.taskId).to.be.defined;
expect(Task.associations.tasksusers.through.rawAttributes.taskId.allowNull).to.be.false; expect(Task.associations.tasksusers.through.model.rawAttributes.taskId.allowNull).to.be.false;
expect(Task.associations.tasksusers.through.rawAttributes.taskId.references).to.equal(Task.getTableName()); expect(Task.associations.tasksusers.through.model.rawAttributes.taskId.references).to.equal(Task.getTableName());
expect(Task.associations.tasksusers.through.rawAttributes.taskId.referencesKey).to.equal('id'); expect(Task.associations.tasksusers.through.model.rawAttributes.taskId.referencesKey).to.equal('id');
expect(Task.associations.tasksusers.through.rawAttributes.uid).to.be.defined; expect(Task.associations.tasksusers.through.model.rawAttributes.uid).to.be.defined;
expect(Task.associations.tasksusers.through.rawAttributes.uid.allowNull).to.be.false; expect(Task.associations.tasksusers.through.model.rawAttributes.uid.allowNull).to.be.false;
expect(Task.associations.tasksusers.through.rawAttributes.uid.references).to.equal(User.getTableName()); expect(Task.associations.tasksusers.through.model.rawAttributes.uid.references).to.equal(User.getTableName());
expect(Task.associations.tasksusers.through.rawAttributes.uid.referencesKey).to.equal('id'); expect(Task.associations.tasksusers.through.model.rawAttributes.uid.referencesKey).to.equal('id');
}); });
it('works when taking a column directly from the object', function () { it('works when taking a column directly from the object', function () {
......
...@@ -976,8 +976,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -976,8 +976,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
t.rollback().success(function(){ done() }) t.rollback().success(function(){ done() })
}) })
}) })
}).on('sql', function (sql) {
console.log(sql);
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!