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

Commit 1aa0c388 by Mick Hansen

Merge branch 'master' of https://github.com/Bugari/sequelize into Bugari-master

2 parents 6bf2a1df ab5f7567
Showing with 100 additions and 0 deletions
...@@ -235,6 +235,106 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -235,6 +235,106 @@ describe(Support.getTestDialectTeaser("Include"), function () {
} }
}) })
it('should accept nested `where` and `limit` at the same time', function (done) {
var Product = this.sequelize.define('Product', {
title: DataTypes.STRING
})
, Tag = this.sequelize.define('Tag', {
name: DataTypes.STRING
})
, ProductTag = this.sequelize.define('ProductTag', {
priority: DataTypes.INTEGER
})
, Set = this.sequelize.define('Set', {
title: DataTypes.STRING
})
Set.hasMany(Product)
Product.belongsTo(Set)
Product.hasMany(Tag, {through: ProductTag})
Tag.hasMany(Product, {through: ProductTag})
this.sequelize.sync({force: true}).then(function () {
return Set.bulkCreate([
{title: 'office'}
])
.then( function() {
return Product.bulkCreate([
{title: 'Chair'},
{title: 'Desk'},
{title: 'Dress'}
])
})
.then( function() {
return Tag.bulkCreate([
{name: 'A'},
{name: 'B'},
{name: 'C'}
]).done(function () {
return Tag.findAll()
})
})
.then(function() {
return Set.findAll()
})
.then(function(sets) {
return [sets, Product.findAll()]
})
.spread( function(sets, products) {
return sets[0].addProduct(products[0])
.then( function() {
return sets[0].addProduct(products[1])
}).then( function() {
return [sets, products]
})
})
.spread( function(sets, products) {
return [sets, products, Tag.findAll()]
})
.spread( function(sets, products, tags) {
return products[0].addTag(tags[0], {priority:1})
.then( function() {
return products[0].addTag(tags[1], {priority:2})
})
.then( function() {
return products[0].addTag(tags[2], {priority:1})
})
.then( function() {
return products[1].addTag(tags[1], {priority:2})
})
.then( function() {
return products[2].addTag(tags[1], {priority:3})
})
.then( function() {
return products[2].addTag(tags[2], {priority:0})
})
})
.then( function() {
return Set.findAll({
include: [
{
model: Product,
include: [
{
model: Tag,
where: {
name: 'A'
}
}]
}],
limit: 1
})
})
.then( function() {
done()
})
.catch(function (err) {
expect(err).not.to.be.ok
done()
})
})
})
it('should support an include with multiple different association types', function (done) { it('should support an include with multiple different association types', function (done) {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, Product = this.sequelize.define('Product', { , Product = this.sequelize.define('Product', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!