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

Commit ab5f7567 by Igor Nawrocki

reworked to use promises

1 parent 16620c02
Showing with 72 additions and 63 deletions
...@@ -254,78 +254,87 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -254,78 +254,87 @@ describe(Support.getTestDialectTeaser("Include"), function () {
Product.hasMany(Tag, {through: ProductTag}) Product.hasMany(Tag, {through: ProductTag})
Tag.hasMany(Product, {through: ProductTag}) Tag.hasMany(Product, {through: ProductTag})
this.sequelize.sync({force: true}).done(function () { this.sequelize.sync({force: true}).then(function () {
async.auto({
sets: function(callback) { return Set.bulkCreate([
Set.bulkCreate([ {title: 'office'}
{title: 'office'} ])
]).done(function () { .then( function() {
Set.findAll().done(callback) return Product.bulkCreate([
}) {title: 'Chair'},
}, {title: 'Desk'},
products: function (callback) { {title: 'Dress'}
Product.bulkCreate([ ])
{title: 'Chair'}, })
{title: 'Desk'}, .then( function() {
{title: 'Dress'} return Tag.bulkCreate([
]).done(function () { {name: 'A'},
Product.findAll().done(callback) {name: 'B'},
}) {name: 'C'}
}, ]).done(function () {
tags: function(callback) { return Tag.findAll()
Tag.bulkCreate([ })
{name: 'A'}, })
{name: 'B'}, .then(function() {
{name: 'C'} return Set.findAll()
]).done(function () { })
Tag.findAll().done(callback) .then(function(sets) {
}) return [sets, Product.findAll()]
}, })
productSets: ['sets','products', function(callback, results) { .spread( function(sets, products) {
var chainer = new Sequelize.Utils.QueryChainer() return sets[0].addProduct(products[0])
chainer.add(results.sets[0].addProduct(results.products[0])) .then( function() {
chainer.add(results.sets[0].addProduct(results.products[1])) return sets[0].addProduct(products[1])
chainer.run().done(callback) }).then( function() {
}], return [sets, products]
productTags: ['products', 'tags', function (callback, results) { })
var chainer = new Sequelize.Utils.QueryChainer() })
chainer.add(results.products[0].addTag(results.tags[0], {priority: 1})) .spread( function(sets, products) {
chainer.add(results.products[0].addTag(results.tags[1], {priority: 2})) return [sets, products, Tag.findAll()]
})
chainer.add(results.products[1].addTag(results.tags[1], {priority: 1})) .spread( function(sets, products, tags) {
return products[0].addTag(tags[0], {priority:1})
chainer.add(results.products[2].addTag(results.tags[0], {priority: 3})) .then( function() {
chainer.add(results.products[2].addTag(results.tags[1], {priority: 1})) return products[0].addTag(tags[1], {priority:2})
chainer.add(results.products[2].addTag(results.tags[2], {priority: 2})) })
.then( function() {
chainer.run().done(callback) return products[0].addTag(tags[2], {priority:1})
}] })
}, function (err) { .then( function() {
expect(err).not.to.be.ok return products[1].addTag(tags[1], {priority:2})
})
Set.findAll({ .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: [ include: [
{ {
model: Product, model: Product,
include: [ include: [
{ {
model: Tag, model: Tag,
where: { where: {
name: 'A' name: 'A'
} }
} }]
]
}], }],
limit: 1 limit: 1
}).done(function (err, products) { })
})
.then( function() {
done()
})
.catch(function (err) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
done() 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!