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

Commit 17a98438 by Will Dawson Committed by Jan Aagaard Meier

Check that parent exists before appending attributes. (#6697)

* Check that parent exists before appending attributes.

* Add changelog line
1 parent 99b811a5
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
- [FIXED] Accept dates as string while using `typeValidation` [#6453](https://github.com/sequelize/sequelize/issues/6453) - [FIXED] Accept dates as string while using `typeValidation` [#6453](https://github.com/sequelize/sequelize/issues/6453)
- [FIXED] - ORDER clause was not included in subquery if `order` option value was provided as plain string (not as an array value) - [FIXED] - ORDER clause was not included in subquery if `order` option value was provided as plain string (not as an array value)
- [FIXED] Issue with belongsTo association and foreign keys [#6400](https://github.com/sequelize/sequelize/issues/6400) - [FIXED] Issue with belongsTo association and foreign keys [#6400](https://github.com/sequelize/sequelize/issues/6400)
- [FIXED] Check that parent exists before appending attributes [#6472](https://github.com/sequelize/sequelize/issues/6472)
# 3.24.1 # 3.24.1
- [FIXED] Add `parent`, `original` and `sql` properties to `UniqueConstraintError` - [FIXED] Add `parent`, `original` and `sql` properties to `UniqueConstraintError`
......
...@@ -269,8 +269,7 @@ var groupJoinData = function(rows, includeOptions, options) { ...@@ -269,8 +269,7 @@ var groupJoinData = function(rows, includeOptions, options) {
topExists = true; topExists = true;
} }
} else { } else {
if (!resultMap[itemHash]) { if (!resultMap[itemHash] && ($parent = resultMap[parentHash])) {
$parent = resultMap[parentHash];
$lastKeyPrefix = lastKeyPrefix(prevKey); $lastKeyPrefix = lastKeyPrefix(prevKey);
if (includeMap[prevKey].association.isSingleAssociation) { if (includeMap[prevKey].association.isSingleAssociation) {
...@@ -356,8 +355,7 @@ var groupJoinData = function(rows, includeOptions, options) { ...@@ -356,8 +355,7 @@ var groupJoinData = function(rows, includeOptions, options) {
topExists = true; topExists = true;
} }
} else { } else {
if (!resultMap[itemHash]) { if (!resultMap[itemHash] && ($parent = resultMap[parentHash])) {
$parent = resultMap[parentHash];
$lastKeyPrefix = lastKeyPrefix(prevKey); $lastKeyPrefix = lastKeyPrefix(prevKey);
if (includeMap[prevKey].association.isSingleAssociation) { if (includeMap[prevKey].association.isSingleAssociation) {
......
...@@ -861,6 +861,103 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -861,6 +861,103 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
describe('properly handles attributes:[] cases', function () {
beforeEach(function () {
var self = this;
self.Animal = this.sequelize.define('Animal', {
name: Sequelize.STRING,
age: Sequelize.INTEGER
});
self.Kingdom = this.sequelize.define('Kingdom', {
name: Sequelize.STRING
});
self.AnimalKingdom = this.sequelize.define('AnimalKingdom', {
relation: Sequelize.STRING,
mutation: Sequelize.BOOLEAN
});
self.Kingdom.belongsToMany(self.Animal, { through: self.AnimalKingdom });
return this.sequelize.sync({ force: true })
.then(function() {
return Sequelize.Promise.all([
self.Animal.create({ name: 'Dog', age: 20 }),
self.Animal.create({ name: 'Cat', age: 30 }),
self.Animal.create({ name: 'Peacock', age: 25 }),
self.Animal.create({ name: 'Fish', age: 100 })
]);
})
.spread(function(a1, a2, a3, a4) {
return Sequelize.Promise.all([
self.Kingdom.create({ name: 'Earth' }),
self.Kingdom.create({ name: 'Water' }),
self.Kingdom.create({ name: 'Wind' })
]).spread(function(k1, k2, k3) {
return Sequelize.Promise.all([
k1.addAnimals([a1, a2]),
k2.addAnimals([a4]),
k3.addAnimals([a3])
]);
});
});
});
it('N:M with ignoring include.attributes only', function () {
return this.Kingdom.findAll({
include:[{
model: this.Animal,
where: { age: { $gte : 29 } },
attributes: []
}]
}).then(function(kingdoms) {
expect(kingdoms.length).to.be.eql(2);
kingdoms.forEach(function(kingdom) {
// include.attributes:[] , model doesn't exists
expect(kingdom.Animals).to.not.exist;
});
});
});
it('N:M with ignoring through.attributes only', function () {
return this.Kingdom.findAll({
include:[{
model: this.Animal,
where: { age: { $gte : 29 } },
through: {
attributes: []
}
}]
}).then(function(kingdoms) {
expect(kingdoms.length).to.be.eql(2);
kingdoms.forEach(function(kingdom) {
expect(kingdom.Animals).to.exist; // include model exists
expect(kingdom.Animals[0].AnimalKingdom).to.not.exist; // through doesn't exists
});
});
});
it('N:M with ignoring include.attributes but having through.attributes', function () {
return this.Kingdom.findAll({
include:[{
model: this.Animal,
where: { age: { $gte : 29 } },
attributes: [],
through: {
attributes: ['mutation']
}
}]
}).then(function(kingdoms) {
expect(kingdoms.length).to.be.eql(2);
kingdoms.forEach(function(kingdom) {
// include.attributes: [], model doesn't exists
expect(kingdom.Animals).to.not.exist;
});
});
});
});
describe('order by eager loaded tables', function() { describe('order by eager loaded tables', function() {
describe('HasMany', function() { describe('HasMany', function() {
beforeEach(function() { beforeEach(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!