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

Commit 101000f9 by Mick Hansen

hotfix for non-where required includes with limits

1 parent a12b5954
Notice: All 1.7.x changes are present in 2.0.x aswell
# v1.7.0-rc7 (next)
# v1.7.0-rc8
- [BUG] fixes bug with required includes without wheres with subqueries
# v1.7.0-rc7
- [BUG] ORDER BY statements when using includes should now be places in the appropriate sub/main query more intelligently.
- [BUG] using include.attributes with primary key attributes specified should no longer result in multiple primary key attributes being selected [#1410](https://github.com/sequelize/sequelize/pull/1410)
- [DEPENDENCIES] all dependencies, including Validator have been updated to the latest versions.
......
......@@ -724,7 +724,7 @@ module.exports = (function() {
var joinQueryItem = generateJoinQuery(include, tableName)
// If not many to many, and we're doing a subquery, add joinQuery to subQueries
if (!include.association.isMultiAssociation && (subQuery && (include.hasIncludeWhere || include.where))) {
if (!include.association.isMultiAssociation && (subQuery && (include.hasIncludeRequired || include.required))) {
subJoinQueries.push(joinQueryItem)
} else {
mainJoinQueries.push(joinQueryItem)
......
......@@ -780,6 +780,55 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
it('should be possible to define a belongsTo include as required with limit', function (done) {
var User = this.sequelize.define('User', {})
, Group = this.sequelize.define('Group', {
name: DataTypes.STRING
})
User.belongsTo(Group)
this.sequelize.sync({force: true}).done(function () {
async.auto({
groups: function (callback) {
Group.bulkCreate([
{name: 'A'},
{name: 'B'}
]).done(function () {
Group.findAll().done(callback)
})
},
users: function (callback) {
User.bulkCreate([{}, {}]).done(function () {
User.findAll().done(callback)
})
},
userGroups: ['users', 'groups', function (callback, results) {
var chainer = new Sequelize.Utils.QueryChainer()
chainer.add(results.users[0].setGroup(results.groups[1]))
chainer.add(results.users[1].setGroup(results.groups[0]))
chainer.run().done(callback)
}]
}, function (err, results) {
expect(err).not.to.be.ok
User.findAll({
include: [
{model: Group, required: true}
],
limit: 1
}).done(function (err, users) {
expect(err).not.to.be.ok
expect(users.length).to.equal(1)
users.forEach(function (user) {
expect(user.group).to.be.ok
})
done()
})
})
})
})
it('should be possible to extend the on clause with a where option on a hasOne include', function (done) {
var User = this.sequelize.define('User', {})
, Project = this.sequelize.define('Project', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!