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

Commit 7cb2f05a by Mick Hansen

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

1 parent 9e3a91ae
......@@ -6,7 +6,7 @@
#### 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`.
- When using association N:M getters the included join table entry is now named singularly, this is now the same as includes.
- The naming of the join table entry for N:M association getters is now singular (like includes)
# v2.0.0-dev13
We are working our way to the first 2.0.0 release candidate.
......
......@@ -44,10 +44,11 @@ module.exports = (function() {
options.include.push({
model: through.model,
as: Utils.singularize(through.model.tableName),
attributes: options.joinTableAttributes,
association: {
isSingleAssociation: true,
source: self.association.source,
target: self.association.target,
source: self.association.target,
target: self.association.source,
identifier: self.association.foreignIdentifier
},
required: true,
......
......@@ -136,7 +136,7 @@ module.exports = (function() {
}));
if (this.targetAssociation) {
this.targetAssociation.through = this.through;
this.targetAssociation.through.model = this.through.model;
}
}
......
......@@ -1737,7 +1737,7 @@ module.exports = (function() {
tableNames[include.model.getTableName()] = true;
if (include.hasOwnProperty('attributes')) {
if (include.attributes) {
include.originalAttributes = include.attributes.slice(0);
include.model.primaryKeyAttributes.forEach(function(attr) {
if (include.attributes.indexOf(attr) === -1) {
......
......@@ -894,9 +894,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}).then(function(projects) {
expect(projects).to.have.length(1);
var project = projects[0];
expect(project.ProjectUsers).to.be.defined;
expect(project.ProjectUser).to.be.defined;
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() {
expect(associationName).not.to.equal(this.User.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') {
expect(through.tableName).to.equal(associationName);
}
......@@ -1393,7 +1393,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(ParanoidTask.options.paranoid).to.be.ok;
_.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() {
_.each([this.UserTasks, this.UserTasks2], function (model) {
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() {
expect(project.UserProjects).to.be.defined;
expect(project.status).not.to.exist;
expect(project.UserProjects.status).to.equal('active');
expect(project.UserProjects.data).to.equal(42);
expect(project.UserProject.status).to.equal('active');
expect(project.UserProject.data).to.equal(42);
});
});
......@@ -1559,8 +1559,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(project.UserProjects).to.be.defined;
expect(project.status).not.to.exist;
expect(project.UserProjects.status).to.equal('active');
expect(project.UserProjects.data).not.to.exist;
expect(project.UserProject.status).to.equal('active');
expect(project.UserProject.data).not.to.exist;
});
});
});
......@@ -1844,9 +1844,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
User.hasMany(Group, { as: 'MyGroups', 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.rawAttributes.UserId).to.exist;
expect(Group.associations.MyUsers.through.rawAttributes.GroupId).to.exist;
expect(Group.associations.MyUsers.through.model === User.associations.MyGroups.through.model);
expect(Group.associations.MyUsers.through.model.rawAttributes.UserId).to.exist;
expect(Group.associations.MyUsers.through.model.rawAttributes.GroupId).to.exist;
});
it("correctly identifies its counterpart when through is a model", function () {
......@@ -1857,10 +1857,10 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
User.hasMany(Group, { as: 'MyGroups', 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.rawAttributes.GroupId).to.exist;
expect(Group.associations.MyUsers.through.model.rawAttributes.UserId).to.exist;
expect(Group.associations.MyUsers.through.model.rawAttributes.GroupId).to.exist;
});
});
});
......@@ -2237,15 +2237,15 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(Task.rawAttributes.uid).not.to.be.defined;
expect(Task.associations.tasksusers.through.rawAttributes.taskId).to.be.defined;
expect(Task.associations.tasksusers.through.rawAttributes.taskId.allowNull).to.be.false;
expect(Task.associations.tasksusers.through.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).to.be.defined;
expect(Task.associations.tasksusers.through.model.rawAttributes.taskId.allowNull).to.be.false;
expect(Task.associations.tasksusers.through.model.rawAttributes.taskId.references).to.equal(Task.getTableName());
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.rawAttributes.uid.allowNull).to.be.false;
expect(Task.associations.tasksusers.through.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).to.be.defined;
expect(Task.associations.tasksusers.through.model.rawAttributes.uid.allowNull).to.be.false;
expect(Task.associations.tasksusers.through.model.rawAttributes.uid.references).to.equal(User.getTableName());
expect(Task.associations.tasksusers.through.model.rawAttributes.uid.referencesKey).to.equal('id');
});
it('works when taking a column directly from the object', function () {
......
......@@ -976,8 +976,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
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!