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

Commit be10f0bc by Sascha Depold

pg support for eager loading

1 parent f096d9be
......@@ -31,7 +31,9 @@ module.exports = (function() {
}
var query = new Query(this.client, this.sequelize, callee, options || {})
self.pendingQueries += 1
return query.run(sql)
.success(function() { self.endQuery.call(self) })
.error(function() { self.endQuery.call(self) })
......
......@@ -233,49 +233,27 @@ module.exports = (function() {
if (options.include) {
var optAttributes = [options.table + '.*']
for (var daoName in options.include) {
if (options.include.hasOwnProperty(daoName)) {
var dao = options.include[daoName]
, daoFactory = dao.daoFactoryManager.getDAO(tableName, {
attribute: 'tableName'
})
, _tableName = addQuotes(dao.tableName)
, association = dao.getAssociation(daoFactory)
if (association.connectorDAO) {
var foreignIdentifier = Object.keys(association.connectorDAO.rawAttributes).filter(function(attrName) {
return (!!attrName.match(/.+Id$/) || !!attrName.match(/.+_id$/)) && (attrName !== association.identifier)
})[0]
query += ' LEFT OUTER JOIN ' + addQuotes(association.connectorDAO.tableName) + ' ON '
query += addQuotes(association.connectorDAO.tableName) + '.'
query += addQuotes(foreignIdentifier) + '='
query += addQuotes(table) + '.' + addQuotes('id')
query += ' LEFT OUTER JOIN ' + addQuotes(dao.tableName) + ' ON '
query += addQuotes(dao.tableName) + '.'
query += addQuotes('id') + '='
query += addQuotes(association.connectorDAO.tableName) + '.' + addQuotes(association.identifier)
} else {
query += ' LEFT OUTER JOIN ' + addQuotes(dao.tableName) + ' ON '
query += addQuotes(association.associationType === 'BelongsTo' ? dao.tableName : tableName) + '.'
query += addQuotes(association.identifier) + '='
query += addQuotes(association.associationType === 'BelongsTo' ? tableName : dao.tableName) + '.' + addQuotes('id')
}
var aliasAssoc = daoFactory.getAssociationByAlias(daoName)
, aliasName = !!aliasAssoc ? addQuotes(daoName) : _tableName
optAttributes = optAttributes.concat(
Object.keys(dao.attributes).map(function(attr) {
return '' +
[_tableName, addQuotes(attr)].join('.') +
' AS "' +
removeQuotes([aliasName, attr].join('.')) + '"'
})
)
}
}
options.include.forEach(function(include) {
var attributes = Object.keys(include.daoFactory.attributes).map(function(attr) {
var template = Utils._.template('"<%= table %>"."<%= attr %>" AS "<%= as %>.<%= attr %>"')
return template({
table: include.daoFactory.tableName,
as: include.as,
attr: attr
})
})
optAttributes = optAttributes.concat(attributes)
var joinQuery = ' LEFT OUTER JOIN "<%= table %>" ON "<%= tableLeft %>"."<%= attrLeft %>" = "<%= tableRight %>"."<%= attrRight %>"'
query += Utils._.template(joinQuery)({
table: include.daoFactory.tableName,
tableLeft: ((include.association.associationType === 'BelongsTo') ? include.daoFactory.tableName : tableName),
attrLeft: 'id',
tableRight: ((include.association.associationType === 'BelongsTo') ? tableName : include.daoFactory.tableName),
attrRight: include.association.identifier
})
})
options.attributes = optAttributes.join(', ')
}
......
......@@ -508,7 +508,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated worker via task.worker', function(done) {
this.Task.find({
where: { id: this.task.id },
where: { title: 'homework' },
include: [ this.Worker ]
}).complete(function(err, task) {
expect(err).toBeNull()
......@@ -544,7 +544,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated task via worker.task', function(done) {
this.Worker.find({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ this.Task ]
}).complete(function(err, worker) {
expect(err).toBeNull()
......@@ -586,7 +586,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated task via worker.task', function(done) {
this.Worker.find({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ { daoFactory: this.Task, as: 'ToDo' } ]
}).complete(function(err, worker) {
expect(err).toBeNull()
......@@ -596,6 +596,16 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
done()
}.bind(this))
})
it('returns the associated task via worker.task when daoFactory is aliased with model', function(done) {
this.Worker.find({
where: { name: 'worker' },
include: [ { model: this.Task, as: 'ToDo' } ]
}).complete(function(err, worker) {
expect(worker.toDo.title).toEqual('homework')
done()
}.bind(this))
})
})
describe('hasMany', function() {
......@@ -622,7 +632,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated tasks via worker.tasks', function(done) {
this.Worker.find({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ this.Task ]
}).complete(function(err, worker) {
expect(err).toBeNull()
......@@ -664,7 +674,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated task via worker.task', function(done) {
this.Worker.find({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ { daoFactory: this.Task, as: 'ToDos' } ]
}).complete(function(err, worker) {
expect(err).toBeNull()
......@@ -674,420 +684,18 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
done()
}.bind(this))
})
it('returns the associated task via worker.task when daoFactory is aliased with model', function(done) {
this.Worker.find({
where: { name: 'worker' },
include: [ { model: this.Task, as: 'ToDos' } ]
}).complete(function(err, worker) {
expect(worker.toDos[0].title).toEqual('homework')
done()
}.bind(this))
})
})
})
// describe('association fetching', function() {
// before(function() {
// this.Task = this.sequelize.define('Task', {
// title: Sequelize.STRING
// })
// this.User = this.sequelize.define('UserWithName', {
// name: Sequelize.STRING
// })
// })
// describe('1:1 associations', function() {
// it('fetches associated objects (1st direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setTask(task).success(function() {
// this.User.find({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Task' ]
// }).success(function(user) {
// expect(user.task).toBeDefined()
// expect(user.task.id).toEqual(task.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches no associated object if none is set (1st direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// this.User.find({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Task' ]
// }).success(function(user) {
// expect(user.task).toEqual(null)
// done()
// })
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects via "as" param (1st direction)', function(done) {
// this.User.hasOne(this.Task, { as: 'Homework' })
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setHomework(task).success(function() {
// this.User.find({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Homework' ]
// }).success(function(user) {
// expect(user.homework).toBeDefined()
// expect(user.homework.id).toEqual(task.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated object (2nd direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.User.create({ name: 'another user' }).success(function(another_user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setTask(task).success(function() {
// this.Task.find({
// where: { 'Tasks.id': 1 },
// include: [ 'UserWithName' ]
// }).success(function(task) {
// expect(task.userWithName).toBeDefined()
// expect(task.userWithName.id).toEqual(user.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches no associated object if none is set (2nd direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.User.create({ name: 'another user' }).success(function(another_user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// this.Task.find({
// where: { 'Tasks.id': 1 },
// include: [ 'UserWithName' ]
// }).success(function(task) {
// expect(task.userWithName).toEqual(null)
// done()
// })
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated object via "as" param (2nd direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User, { as: 'Owner' })
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.User.create({ name: 'another user' }).success(function(another_user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setTask(task).success(function() {
// this.Task.find({
// where: { 'Tasks.id': 1 },
// include: [ 'Owner' ]
// }).success(function(task) {
// expect(task.owner).toBeDefined()
// expect(task.owner.id).toEqual(user.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// })
// it('fetches associated objects for 1:N associations (1st direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setTasks([task1, task2]).success(function() {
// this.User.find({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Task' ]
// }).success(function(user) {
// expect(user.tasks).toBeDefined()
// expect(
// user.tasks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects via "as" param for 1:N associations (1st direction)', function(done) {
// this.User.hasMany(this.Task, { as: 'Homeworks' })
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setHomeworks([task1, task2]).success(function() {
// this.User.find({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Homeworks' ]
// }).success(function(user) {
// expect(user.homeworks).toBeDefined()
// expect(
// user.homeworks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches no associated objects for 1:N associations if none are set (1st direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.User.find({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Task' ]
// }).success(function(user) {
// expect(user.tasks.length).toEqual(0)
// done()
// })
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:N associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setTasks([task1, task2]).success(function() {
// this.Task.find({
// where: { 'Tasks.id': 1 },
// include: [ 'UserWithName' ]
// }).success(function(task) {
// expect(task.userWithName).toBeDefined()
// expect(task.userWithName.name).toEqual(user.name)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects via "as" param for 1:N associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User, { as: 'Owner'})
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setTasks([task1, task2]).success(function() {
// this.Task.find({
// where: { 'Tasks.id': 1 },
// include: [ 'Owner' ]
// }).success(function(task) {
// expect(task.owner).toBeDefined()
// expect(task.owner.name).toEqual(user.name)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for N:M associations (1st direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.hasMany(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setTasks([task1, task2]).success(function() {
// this.User.find({
// where: { 'UserWithNames.id': user1.id },
// include: [ 'Task' ]
// }).success(function(user) {
// expect(user.tasks).toBeDefined()
// expect(
// user.tasks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches no associated objects for N:M associations if none are set (1st direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.hasMany(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// this.User.find({
// where: { 'UserWithNames.id': user1.id },
// include: [ 'Task' ]
// }).success(function(user) {
// expect(user.tasks.length).toEqual(0)
// done()
// })
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects via "as" param for N:M associations (1st direction)', function(done) {
// this.User.hasMany(this.Task, { as: 'Homeworks' })
// this.Task.hasMany(this.User, { as: 'Owners' })
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setHomeworks([task1, task2]).success(function() {
// this.User.find({
// where: { 'UserWithNames.id': user1.id },
// include: [ 'Homeworks' ]
// }).success(function(user) {
// expect(user.homeworks).toBeDefined()
// expect(
// user.homeworks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for N:M associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.hasMany(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setTasks([task1, task2]).success(function() {
// this.Task.find({
// where: { 'Tasks.id': task1.id },
// include: [ 'UserWithName' ]
// }).success(function(task) {
// expect(task.userWithNames).toBeDefined()
// expect(
// task.userWithNames.map(function(u) { return u.id })
// ).toEqual(
// [ user1.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects via "as" param for N:M associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task, { as: 'Homeworks' })
// this.Task.hasMany(this.User, { as: 'Owners' })
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setHomeworks([task1, task2]).success(function() {
// this.Task.find({
// where: { 'Tasks.id': task1.id },
// include: [ 'Owners' ]
// }).success(function(task) {
// expect(task.owners).toBeDefined()
// expect(
// task.owners.map(function(u) { return u.id })
// ).toEqual(
// [ user1.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// })
}) //- describe: find
describe('findAll', function findAll() {
......@@ -1133,7 +741,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated worker via task.worker', function(done) {
this.Task.findAll({
where: { id: this.task.id },
where: { title: 'homework' },
include: [ this.Worker ]
}).complete(function(err, tasks) {
expect(err).toBeNull()
......@@ -1169,7 +777,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated task via worker.task', function(done) {
this.Worker.findAll({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ this.Task ]
}).complete(function(err, workers) {
expect(err).toBeNull()
......@@ -1211,7 +819,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated task via worker.task', function(done) {
this.Worker.findAll({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ { daoFactory: this.Task, as: 'ToDo' } ]
}).complete(function(err, workers) {
expect(err).toBeNull()
......@@ -1221,6 +829,16 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
done()
}.bind(this))
})
it('returns the associated task via worker.task when daoFactory is aliased with model', function(done) {
this.Worker.findAll({
where: { name: 'worker' },
include: [ { model: this.Task, as: 'ToDo' } ]
}).complete(function(err, workers) {
expect(workers[0].toDo.title).toEqual('homework')
done()
}.bind(this))
})
})
describe('hasMany', function() {
......@@ -1247,7 +865,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated tasks via worker.tasks', function(done) {
this.Worker.findAll({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ this.Task ]
}).complete(function(err, workers) {
expect(err).toBeNull()
......@@ -1289,7 +907,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
it('returns the associated task via worker.task', function(done) {
this.Worker.findAll({
where: { id: this.worker.id },
where: { name: 'worker' },
include: [ { daoFactory: this.Task, as: 'ToDos' } ]
}).complete(function(err, workers) {
expect(err).toBeNull()
......@@ -1299,360 +917,18 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
done()
}.bind(this))
})
it('returns the associated task via worker.task when daoFactory is aliased with model', function(done) {
this.Worker.findAll({
where: { name: 'worker' },
include: [ { daoFactory: this.Task, as: 'ToDos' } ]
}).complete(function(err, workers) {
expect(workers[0].toDos[0].title).toEqual('homework')
done()
}.bind(this))
})
})
})
// describe('include', function() {
// before(function() {
// this.Task = this.sequelize.define('Task', {
// title: Sequelize.STRING
// })
// this.User = this.sequelize.define('UserWithName', {
// name: Sequelize.STRING
// })
// })
// it('fetches data only for the relevant where clause', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.User.create({ name: 'barfooz' }).success(function(user2) {
// this.Task.create({ title: 'task' }).success(function(task) {
// var where = [Sequelize.Utils.addTicks(this.User.tableName) + ".`id`=?", user1.id]
// if (dialect === 'postgres') {
// where = ['"' + this.User.tableName + '"."id"=?', user1.id]
// }
// this.User.findAll({
// where: where,
// include: [ 'Task' ]
// }).success(function(users){
// expect(users.length).toEqual(1)
// // console.log(users[0])
// done()
// }.bind(this))
// }.bind(this))
// }.bind(this))
// }.bind(this))
// }.bind(this))
// })
// it('fetches associated objects for 1:1 associations (1st direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setTask(task).success(function() {
// this.User.findAll({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Task' ]
// }).success(function(users) {
// expect(users[0].task).toBeDefined()
// expect(users[0].task.id).toEqual(task.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects via "as" param for 1:1 associations (1st direction)', function(done) {
// this.User.hasOne(this.Task, { as: 'Homework' })
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setHomework(task).success(function() {
// this.User.findAll({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Homework' ]
// }).success(function(users) {
// expect(users[0].homework).toBeDefined()
// expect(users[0].homework.id).toEqual(task.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:1 associations (2nd direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setTask(task).success(function() {
// this.Task.findAll({
// where: { 'Tasks.id': 1 },
// include: [ 'UserWithName' ]
// }).success(function(tasks) {
// expect(tasks[0].userWithName).toBeDefined()
// expect(tasks[0].userWithName.id).toEqual(user.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:1 associations (2nd direction)', function(done) {
// this.User.hasOne(this.Task)
// this.Task.belongsTo(this.User, { as: 'Owner' })
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task' }).success(function(task) {
// user.setTask(task).success(function() {
// this.Task.findAll({
// where: { 'Tasks.id': 1 },
// include: [ 'Owner' ]
// }).success(function(tasks) {
// expect(tasks[0].owner).toBeDefined()
// expect(tasks[0].owner.id).toEqual(user.id)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:N associations (1st direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setTasks([task1, task2]).success(function() {
// this.User.findAll({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Task' ]
// }).success(function(users) {
// expect(users[0].tasks).toBeDefined()
// expect(
// users[0].tasks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:N associations (1st direction)', function(done) {
// this.User.hasMany(this.Task, { as: 'Homeworks' })
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setHomeworks([task1, task2]).success(function() {
// this.User.findAll({
// where: { 'UserWithNames.id': 1 },
// include: [ 'Homeworks' ]
// }).success(function(users) {
// expect(users[0].homeworks).toBeDefined()
// expect(
// users[0].homeworks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:N associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setTasks([task1, task2]).success(function() {
// this.Task.findAll({
// where: { 'Tasks.id': 1 },
// include: [ 'UserWithName' ]
// }).success(function(tasks) {
// expect(tasks[0].userWithName).toBeDefined()
// expect(tasks[0].userWithName.name).toEqual(user.name)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for 1:N associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.belongsTo(this.User, { as: 'Owner' })
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user.setTasks([task1, task2]).success(function() {
// this.Task.findAll({
// where: { 'Tasks.id': 1 },
// include: [ 'Owner' ]
// }).success(function(tasks) {
// expect(tasks[0].owner).toBeDefined()
// expect(tasks[0].owner.name).toEqual(user.name)
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for N:M associations (1st direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.hasMany(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setTasks([task1, task2]).success(function() {
// this.User.findAll({
// where: { 'UserWithNames.id': user1.id },
// include: [ 'Task' ]
// }).success(function(users) {
// expect(users[0].tasks).toBeDefined()
// expect(
// users[0].tasks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for N:M associations (1st direction)', function(done) {
// this.User.hasMany(this.Task, { as: 'Homeworks' })
// this.Task.hasMany(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setHomeworks([task1, task2]).success(function() {
// this.User.findAll({
// where: { 'UserWithNames.id': user1.id },
// include: [ 'Homeworks' ]
// }).success(function(users) {
// expect(users[0].homeworks).toBeDefined()
// expect(
// users[0].homeworks.map(function(t) { return t.id })
// ).toEqual(
// [ task1.id, task2.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for N:M associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.hasMany(this.User)
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setTasks([task1, task2]).success(function() {
// this.Task.findAll({
// where: { 'Tasks.id': task1.id },
// include: [ 'UserWithName' ]
// }).success(function(tasks) {
// expect(tasks[0].userWithNames).toBeDefined()
// expect(
// tasks[0].userWithNames.map(function(u) { return u.id })
// ).toEqual(
// [ user1.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// it('fetches associated objects for N:M associations (2nd direction)', function(done) {
// this.User.hasMany(this.Task)
// this.Task.hasMany(this.User, { as: 'Owners' })
// this.sequelize.sync({ force: true }).success(function() {
// this.User.create({ name: 'barfooz' }).success(function(user1) {
// this.Task.create({ title: 'task1' }).success(function(task1) {
// this.Task.create({ title: 'task2' }).success(function(task2) {
// user1.setTasks([task1, task2]).success(function() {
// this.Task.findAll({
// where: { 'Tasks.id': task1.id },
// include: [ 'Owners' ]
// }).success(function(tasks) {
// expect(tasks[0].owners).toBeDefined()
// expect(
// tasks[0].owners.map(function(u) { return u.id })
// ).toEqual(
// [ user1.id ]
// )
// done()
// })
// }.bind(this)) //- setTask
// }.bind(this)) //- Task.create
// }.bind(this)) //- Task.create
// }.bind(this)) //- User.create
// }.bind(this)) //- sequelize.sync
// })
// })
}) //- describe: findAll
describe('min', function() {
......
if(typeof require === 'function') {
if (typeof require === 'function') {
const buster = require("buster")
, Helpers = require('./buster-helpers')
, dialect = Helpers.getTestDialect()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!