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

Commit 739ed5c6 by Mick Hansen

Merge pull request #1615 from cusspvz/master

Test for #1614
2 parents b1e94268 cb3444a4
...@@ -779,7 +779,7 @@ module.exports = (function() { ...@@ -779,7 +779,7 @@ module.exports = (function() {
joinQueryItem += " AND "+self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.daoFactory, whereOptions) joinQueryItem += " AND "+self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.daoFactory, whereOptions)
// If its a multi association we need to add a where query to the main where (executed in the subquery) // If its a multi association we need to add a where query to the main where (executed in the subquery)
if (subQuery && association.isMultiAssociation) { if (subQuery && association.isMultiAssociation && include.required) {
if (!options.where) options.where = {} if (!options.where) options.where = {}
// Creating the as-is where for the subQuery, checks that the required association exists // Creating the as-is where for the subQuery, checks that the required association exists
......
...@@ -698,6 +698,30 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -698,6 +698,30 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}) })
}) })
it("get associated objects with an eager load with conditions but not required", function(done) {
var Label = this.sequelize.define('Label', { 'title': DataTypes.STRING, 'isActive': DataTypes.BOOLEAN })
, Task = this.Task
, User = this.User
Task.hasMany(Label)
Label.sync({ force: true }).success(function() {
User.find({
where: { username: 'John'},
include: [
{ model: Task, required: false, include: [
{ model: Label, required: false, where: { isActive: true } }
]}
]
}).done(function (err, john) {
expect(err).not.to.be.ok
expect(john.tasks).to.have.length(2);
done();
})
})
})
it('should support schemas', function (done) { it('should support schemas', function (done) {
var self = this var self = this
, AcmeUser = self.sequelize.define('User', { , AcmeUser = self.sequelize.define('User', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!