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

Commit 8b1ab8bb by Mick Hansen

fix(include.seperate): dont break in cases where a result has a non seperate emp…

…ty include with a nested include
1 parent e24bbce8
# 3.5.1
- [FIXED] Fix bug with nested includes where a middle include results in a null value which breaks $findSeperate.
# 3.5.0
- [ADDED] `include.seperate` with `include.limit` support for HasMany associations.
- [ADDED] Added default validation based on attribute types. [#3472](https://github.com/sequelize/sequelize/pull/3472). The validation _cannot_ be disabled. If you really want to completely disable it, you can remove the `validate` function from the corresponding datatype, but know that this permanently disables the validation.
......
......@@ -1342,6 +1342,11 @@ Model.$findSeperate = function(results, options) {
return Model.$findSeperate(
results.reduce(function (memo, result) {
var associations = result.get(include.association.as);
// Might be an empty belongsTo relation
if (!associations) return memo;
// Force array so we can concat no matter if it's 1:1 or :M
if (!Array.isArray(associations)) associations = [associations];
return memo.concat(associations);
......
......@@ -59,6 +59,25 @@ if (current.dialect.supports.groupedLimit) {
});
});
it('should not break a nested include with null values', function () {
var User = this.sequelize.define('User', {})
, Team = this.sequelize.define('Team', {})
, Company = this.sequelize.define('Company', {});
User.Team = User.belongsTo(Team);
Team.Company = Team.belongsTo(Company);
return this.sequelize.sync({force: true}).then(function () {
return User.create({});
}).then(function () {
return User.findAll({
include: [
{association: User.Team, include: [Team.Company]}
]
});
});
});
it('should run a hasMany association with limit in a separate query', function () {
var User = this.sequelize.define('User', {})
, Task = this.sequelize.define('Task', {})
......
......@@ -9,7 +9,7 @@ var Support = require(__dirname + '/../support')
describe(Support.getTestDialectTeaser('SQL'), function() {
describe.only('createTable', function () {
describe('createTable', function () {
describe('with enums', function () {
var FooUser = current.define('user', {
mood: DataTypes.ENUM('happy', 'sad')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!