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

Commit 05426e62 by Mick Hansen

Merge pull request #2474 from overlookmotel/model-names-fix

User model names rather than singularized table names
2 parents 2ad7673d b51a9f01
......@@ -2,6 +2,9 @@
- [BUG] Add support for `field` named the same as the attribute in `reload`, `bulkCreate` and `save` [#2348](https://github.com/sequelize/sequelize/issues/2348)
- [BUG] Copy the options object in association getters. [#2311](https://github.com/sequelize/sequelize/issues/2311)
#### Backwards compatability changes
- When eager-loading a many-to-many association, the attributes of the through table are now accessible through an attribute named after the through model rather than the through table name singularized. i.e. `Task.find({include: Worker})` where the table name for through model `TaskWorker` is `TableTaskWorkers` used to produce `{ Worker: { ..., TableTaskWorker: {...} } }`. It now produces `{ Worker: { ..., TaskWorker: {...} } }`. Does not affect models where table name is auto-defined by Sequelize, or where table name is model name pluralized.
# 2.0.0-rc2
- [FEATURE] Added to posibility of using a sequelize object as key in `sequelize.where`. Also added the option of specifying a comparator
- [FEATURE] Added countercache functionality to hasMany associations [#2375](https://github.com/sequelize/sequelize/pull/2375)
......
......@@ -43,7 +43,7 @@ module.exports = (function() {
options.include = options.include || [];
options.include.push({
model: through.model,
as: Utils.singularize(through.model.tableName),
as: through.model.name,
attributes: options.joinTableAttributes,
association: {
isSingleAssociation: true,
......
......@@ -557,7 +557,7 @@ module.exports = (function() {
// check if model provided is through table
if (!as && parentAssociation && parentAssociation.through && parentAssociation.through.model === model) {
association = {as: Utils.singularize(model.tableName, model.options.language)};
association = {as: model.name};
} else {
// find applicable association for linking parent to this model
association = parent.getAssociation(model, as);
......
......@@ -1853,7 +1853,7 @@ module.exports = (function() {
include.through = Utils._.defaults(include.through || {}, {
model: through.model,
as: Utils.singularize(through.model.tableName),
as: through.model.name,
association: {
isSingleAssociation: true
},
......
......@@ -939,9 +939,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}).then(function(projects) {
expect(projects).to.have.length(1);
var project = projects[0];
expect(project.ProjectUser).to.be.defined;
expect(project.ProjectUsers).to.be.defined;
expect(project.status).not.to.exist;
expect(project.ProjectUser.status).to.equal('active');
expect(project.ProjectUsers.status).to.equal('active');
});
});
});
......@@ -1778,8 +1778,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(project.UserProjects).to.be.defined;
expect(project.status).not.to.exist;
expect(project.UserProject.status).to.equal('active');
expect(project.UserProject.data).to.equal(42);
expect(project.UserProjects.status).to.equal('active');
expect(project.UserProjects.data).to.equal(42);
});
});
......@@ -1796,8 +1796,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
expect(project.UserProjects).to.be.defined;
expect(project.status).not.to.exist;
expect(project.UserProject.status).to.equal('active');
expect(project.UserProject.data).not.to.exist;
expect(project.UserProjects.status).to.equal('active');
expect(project.UserProjects.data).not.to.exist;
});
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!