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

You need to sign in or sign up before continuing.
Commit 52311582 by Chris Wilhelm

Unit tests added for .find() and .findAll(), with included relation using own wh…

…ere and require: false.
1 parent 39391483
......@@ -53,7 +53,38 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
});
it("should still pull the main record when an included model is not required and has where restrictions without matches", function () {
var DT = DataTypes,
S = this.sequelize,
A = S.define( 'A', {name: DT.STRING(40)} ),
B = S.define( 'B', {name: DT.STRING(40)} );
A.hasMany(B);
B.hasMany(A);
return S
.sync({force: true})
.then(function () {
return A.create({
name: 'Foobar'
});
})
.then(function () {
return A.find({
where: {name: 'Foobar'},
include: [
{model: B, where: {name: 'idontexist'}, require: false}
]
});
})
.then(function (a) {
expect(a).to.not.equal(null);
expect(a.get('bs')).to.deep.equal([]);
});
});
});
})
\ No newline at end of file
......@@ -1679,5 +1679,38 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
it("should still pull the main record(s) when an included model is not required and has where restrictions without matches", function () {
var DT = DataTypes,
S = this.sequelize,
A = S.define( 'A', {name: DT.STRING(40)} ),
B = S.define( 'B', {name: DT.STRING(40)} );
A.hasMany(B);
B.hasMany(A);
return S
.sync({force: true})
.then(function () {
return A.create({
name: 'Foobar'
});
})
.then(function () {
return A.findAll({
where: {name: 'Foobar'},
include: [
{model: B, where: {name: 'idontexist'}, require: false}
]
});
})
.then(function (as) {
expect(as.length).to.equal(1);
expect(as[0].get('bs')).deep.equal([]);
});
});
})
})
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!