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

Commit ba77f7dc by Mick Hansen

fix(include): query shouldn't include multiple duplicate primary key attributes …

…if having primary keys in include.attributes
1 parent c8235a54
Showing with 37 additions and 2 deletions
...@@ -1768,7 +1768,11 @@ module.exports = (function() { ...@@ -1768,7 +1768,11 @@ module.exports = (function() {
if (include.hasOwnProperty('attributes')) { if (include.hasOwnProperty('attributes')) {
include.originalAttributes = include.attributes; include.originalAttributes = include.attributes;
include.attributes = include.attributes.concat(include.model.primaryKeyAttributes) include.model.primaryKeyAttributes.forEach(function (attr) {
if (include.attributes.indexOf(attr) === -1) {
include.attributes.unshift(attr);
}
});
} else { } else {
include.attributes = Object.keys(include.model.attributes) include.attributes = Object.keys(include.model.attributes)
} }
......
...@@ -1427,7 +1427,7 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -1427,7 +1427,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
var self = this var self = this
this.fixtureA(function () { this.fixtureA(function () {
self.models.Product.findAll({ self.models.Product.findAll({
attributes: ['title'], attributes: ['id', 'title'],
include: [ include: [
{model: self.models.Company, where: {name: 'NYSE'}}, {model: self.models.Company, where: {name: 'NYSE'}},
{model: self.models.Tag}, {model: self.models.Tag},
...@@ -1451,6 +1451,37 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -1451,6 +1451,37 @@ describe(Support.getTestDialectTeaser("Include"), function () {
}) })
}) })
it('should be possible to have the primary key in attributes', function () {
var Parent = this.sequelize.define('Parent', {});
var Child1 = this.sequelize.define('Child1', {});
Parent.hasMany(Child1);
Child1.belongsTo(Parent);
return this.sequelize.sync({force: true}).then(function () {
return Sequelize.Promise.all([
Parent.create(),
Child1.create()
]);
}).spread(function (parent, child) {
return parent.addChild1(child).then(function () {
return parent;
});
}).then(function (parent) {
return Child1.find({
include: [
{
model: Parent,
attributes: ['id'], // This causes a duplicated entry in the query
where: {
id: parent.id
}
}
]
});
});
});
it('should be possible to turn off the attributes for the through table', function (done) { it('should be possible to turn off the attributes for the through table', function (done) {
var self = this var self = this
this.fixtureA(function () { this.fixtureA(function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!