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

Commit 14ca4e6e by Sascha Depold

mysql is working :)

1 parent 4281e799
...@@ -143,23 +143,16 @@ module.exports = (function() { ...@@ -143,23 +143,16 @@ module.exports = (function() {
var hasJoin = false var hasJoin = false
var options = Utils._.clone(options) var options = Utils._.clone(options)
if ((typeof options === 'object') && (options.hasOwnProperty('include'))) { if (typeof options === 'object') {
var includes = options.include hasJoin = true
hasJoin = true if (options.hasOwnProperty('include')) {
options.include = {} hasJoin = true
/*options.include =*/ includes.map(function(include) {
console.log(include instanceof DAOFactory)
})
includes.forEach(function(daoName) {
options.include[daoName] = this.daoFactoryManager.getDAO(daoName)
if (!options.include[daoName]) { options.include = options.include.map(function(include) {
options.include[daoName] = this.getAssociationByAlias(daoName).target return validateIncludedElement.call(this, include)
} }.bind(this))
}.bind(this)) }
// whereCollection is used for non-primary key updates // whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null this.options.whereCollection = options.where || null
......
...@@ -198,6 +198,8 @@ module.exports = (function() { ...@@ -198,6 +198,8 @@ module.exports = (function() {
} }
QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) { QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) {
options = options || {}
var sql = this.QueryGenerator.selectQuery(tableName, options) var sql = this.QueryGenerator.selectQuery(tableName, options)
queryOptions = Utils._.extend({}, queryOptions, { include: options.include }) queryOptions = Utils._.extend({}, queryOptions, { include: options.include })
return queryAndEmit.call(this, [sql, factory, queryOptions], 'select') return queryAndEmit.call(this, [sql, factory, queryOptions], 'select')
......
...@@ -472,7 +472,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -472,7 +472,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
this.Worker = this.sequelize.define('Worker', { name: Sequelize.STRING }) this.Worker = this.sequelize.define('Worker', { name: Sequelize.STRING })
}) })
describe('=>belongsTo', function() { describe('belongsTo', function() {
before(function(done) { before(function(done) {
this.Task.belongsTo(this.Worker) this.Task.belongsTo(this.Worker)
...@@ -520,7 +520,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -520,7 +520,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
describe('=>hasOne', function() { describe('hasOne', function() {
before(function(done) { before(function(done) {
this.Worker.hasOne(this.Task) this.Worker.hasOne(this.Task)
...@@ -556,7 +556,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -556,7 +556,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
describe('=>hasOne with alias', function() { describe('hasOne with alias', function() {
before(function(done) { before(function(done) {
this.Worker.hasOne(this.Task, { as: 'ToDo' }) this.Worker.hasOne(this.Task, { as: 'ToDo' })
...@@ -598,7 +598,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -598,7 +598,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
describe('=>hasMany', function() { describe('hasMany', function() {
before(function(done) { before(function(done) {
this.Worker.hasMany(this.Task) this.Worker.hasMany(this.Task)
...@@ -634,7 +634,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -634,7 +634,7 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
describe('=>hasMany with alias', function() { describe('hasMany with alias', function() {
before(function(done) { before(function(done) {
this.Worker.hasMany(this.Task, { as: 'ToDos' }) this.Worker.hasMany(this.Task, { as: 'ToDos' })
...@@ -1091,357 +1091,568 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -1091,357 +1091,568 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) //- describe: find }) //- describe: find
describe('findAll', function findAll() { describe('findAll', function findAll() {
describe('include', function() { describe('eager loading', function() {
before(function() { before(function() {
this.Task = this.sequelize.define('Task', { this.Task = this.sequelize.define('Task', { title: Sequelize.STRING })
title: Sequelize.STRING this.Worker = this.sequelize.define('Worker', { name: Sequelize.STRING })
})
describe('belongsTo', function() {
before(function(done) {
this.Task.belongsTo(this.Worker)
this.sequelize.sync({ force: true }).complete(function() {
this.Worker.create({ name: 'worker' }).success(function(worker) {
this.Task.create({ title: 'homework' }).success(function(task) {
this.worker = worker
this.task = task
this.task.setWorker(this.worker).success(done)
}.bind(this))
}.bind(this))
}.bind(this))
})
it('throws an error about unexpected input if include contains a non-object', function() {
Helpers.assertException(function() {
this.Worker.findAll({ include: [ 1 ] })
}.bind(this), 'Include unexpected. Element has to be either an instance of DAOFactory or an object.')
})
it('throws an error about missing attributes if include contains an object with daoFactory', function() {
Helpers.assertException(function() {
this.Worker.findAll({ include: [ { daoFactory: this.Worker } ] })
}.bind(this), 'Include malformed. Expected attributes: daoFactory, as!')
})
it('throws an error if included DaoFactory is not associated', function() {
Helpers.assertException(function() {
this.Worker.findAll({ include: [ this.Task ] })
}.bind(this), 'Task is not associated to Worker!')
}) })
this.User = this.sequelize.define('UserWithName', { it('returns the associated worker via task.worker', function(done) {
name: Sequelize.STRING this.Task.findAll({
where: { id: this.task.id },
include: [ this.Worker ]
}).complete(function(err, tasks) {
expect(err).toBeNull()
expect(tasks).toBeDefined()
expect(tasks[0].worker).toBeDefined()
expect(tasks[0].worker.name).toEqual('worker')
done()
}.bind(this))
}) })
}) })
it('fetches data only for the relevant where clause', function(done) { describe('hasOne', function() {
this.User.hasOne(this.Task) before(function(done) {
this.Task.belongsTo(this.User) this.Worker.hasOne(this.Task)
this.sequelize.sync({ force: true }).success(function() { this.sequelize.sync({ force: true }).complete(function() {
this.User.create({ name: 'barfooz' }).success(function(user1) { this.Worker.create({ name: 'worker' }).success(function(worker) {
this.User.create({ name: 'barfooz' }).success(function(user2) { this.Task.create({ title: 'homework' }).success(function(task) {
this.Task.create({ title: 'task' }).success(function(task) { this.worker = worker
var where = [Sequelize.Utils.addTicks(this.User.tableName) + ".`id`=?", user1.id] this.task = task
if (dialect === 'postgres') { this.worker.setTask(this.task).success(done)
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))
}.bind(this)) }.bind(this))
}.bind(this)) })
})
it('fetches associated objects for 1:1 associations (1st direction)', function(done) { it('throws an error if included DaoFactory is not associated', function() {
this.User.hasOne(this.Task) Helpers.assertException(function() {
this.Task.belongsTo(this.User) this.Task.findAll({ include: [ this.Worker ] })
}.bind(this), 'Worker is not associated to Task!')
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) { it('returns the associated task via worker.task', function(done) {
this.User.hasOne(this.Task, { as: 'Homework' }) this.Worker.findAll({
this.Task.belongsTo(this.User) where: { id: this.worker.id },
include: [ this.Task ]
this.sequelize.sync({ force: true }).success(function() { }).complete(function(err, workers) {
this.User.create({ name: 'barfooz' }).success(function(user) { expect(err).toBeNull()
this.Task.create({ title: 'task' }).success(function(task) { expect(workers).toBeDefined()
user.setHomework(task).success(function() { expect(workers[0].task).toBeDefined()
this.User.findAll({ expect(workers[0].task.title).toEqual('homework')
where: { 'UserWithNames.id': 1 }, done()
include: [ 'Homework' ] }.bind(this))
}).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) { describe('hasOne with alias', function() {
this.User.hasOne(this.Task) before(function(done) {
this.Task.belongsTo(this.User) this.Worker.hasOne(this.Task, { as: 'ToDo' })
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.sequelize.sync({ force: true }).complete(function() {
this.User.hasOne(this.Task) this.Worker.create({ name: 'worker' }).success(function(worker) {
this.Task.belongsTo(this.User, { as: 'Owner' }) this.Task.create({ title: 'homework' }).success(function(task) {
this.worker = worker
this.sequelize.sync({ force: true }).success(function() { this.task = task
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.worker.setToDo(this.task).success(done)
this.User.hasMany(this.Task) }.bind(this))
this.Task.belongsTo(this.User) }.bind(this))
}.bind(this))
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) { it('throws an error if included DaoFactory is not referenced by alias', function() {
this.User.hasMany(this.Task, { as: 'Homeworks' }) Helpers.assertException(function() {
this.Task.belongsTo(this.User) this.Worker.findAll({ include: [ this.Task ] })
}.bind(this), 'Task is not associated to Worker!')
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) { it('throws an error if alias is not associated', function() {
this.User.hasMany(this.Task) Helpers.assertException(function() {
this.Task.belongsTo(this.User) this.Worker.findAll({ include: [ { daoFactory: this.Task, as: 'Work' } ] })
}.bind(this), 'Task (Work) is not associated to Worker!')
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) { it('returns the associated task via worker.task', function(done) {
this.User.hasMany(this.Task) this.Worker.findAll({
this.Task.belongsTo(this.User, { as: 'Owner' }) where: { id: this.worker.id },
include: [ { daoFactory: this.Task, as: 'ToDo' } ]
this.sequelize.sync({ force: true }).success(function() { }).complete(function(err, workers) {
this.User.create({ name: 'barfooz' }).success(function(user) { expect(err).toBeNull()
this.Task.create({ title: 'task1' }).success(function(task1) { expect(workers).toBeDefined()
this.Task.create({ title: 'task2' }).success(function(task2) { expect(workers[0].toDo).toBeDefined()
user.setTasks([task1, task2]).success(function() { expect(workers[0].toDo.title).toEqual('homework')
this.Task.findAll({ done()
where: { 'Tasks.id': 1 }, }.bind(this))
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) { describe('hasMany', function() {
this.User.hasMany(this.Task) before(function(done) {
this.Task.hasMany(this.User) this.Worker.hasMany(this.Task)
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.sequelize.sync({ force: true }).complete(function() {
this.User.hasMany(this.Task, { as: 'Homeworks' }) this.Worker.create({ name: 'worker' }).success(function(worker) {
this.Task.hasMany(this.User) this.Task.create({ title: 'homework' }).success(function(task) {
this.worker = worker
this.sequelize.sync({ force: true }).success(function() { this.task = task
this.User.create({ name: 'barfooz' }).success(function(user1) {
this.worker.setTasks([ this.task ]).success(done)
this.Task.create({ title: 'task1' }).success(function(task1) { }.bind(this))
this.Task.create({ title: 'task2' }).success(function(task2) { }.bind(this))
user1.setHomeworks([task1, task2]).success(function() { }.bind(this))
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) { it('throws an error if included DaoFactory is not associated', function() {
this.User.hasMany(this.Task) Helpers.assertException(function() {
this.Task.hasMany(this.User) this.Task.findAll({ include: [ this.Worker ] })
}.bind(this), 'Worker is not associated to Task!')
this.sequelize.sync({ force: true }).success(function() { })
this.User.create({ name: 'barfooz' }).success(function(user1) {
it('returns the associated tasks via worker.tasks', function(done) {
this.Task.create({ title: 'task1' }).success(function(task1) { this.Worker.findAll({
this.Task.create({ title: 'task2' }).success(function(task2) { where: { id: this.worker.id },
user1.setTasks([task1, task2]).success(function() { include: [ this.Task ]
this.Task.findAll({ }).complete(function(err, workers) {
where: { 'Tasks.id': task1.id }, expect(err).toBeNull()
include: [ 'UserWithName' ] expect(workers).toBeDefined()
}).success(function(tasks) { expect(workers[0].tasks).toBeDefined()
expect(tasks[0].userWithNames).toBeDefined() expect(workers[0].tasks[0].title).toEqual('homework')
expect( done()
tasks[0].userWithNames.map(function(u) { return u.id }) }.bind(this))
).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) { describe('hasMany with alias', function() {
this.User.hasMany(this.Task) before(function(done) {
this.Task.hasMany(this.User, { as: 'Owners' }) this.Worker.hasMany(this.Task, { as: 'ToDos' })
this.sequelize.sync({ force: true }).success(function() { this.sequelize.sync({ force: true }).complete(function() {
this.User.create({ name: 'barfooz' }).success(function(user1) { this.Worker.create({ name: 'worker' }).success(function(worker) {
this.Task.create({ title: 'homework' }).success(function(task) {
this.Task.create({ title: 'task1' }).success(function(task1) { this.worker = worker
this.Task.create({ title: 'task2' }).success(function(task2) { this.task = task
user1.setTasks([task1, task2]).success(function() {
this.Task.findAll({ this.worker.setToDos([ this.task ]).success(done)
where: { 'Tasks.id': task1.id }, }.bind(this))
include: [ 'Owners' ] }.bind(this))
}).success(function(tasks) { }.bind(this))
expect(tasks[0].owners).toBeDefined() })
expect(
tasks[0].owners.map(function(u) { return u.id }) it('throws an error if included DaoFactory is not referenced by alias', function() {
).toEqual( Helpers.assertException(function() {
[ user1.id ] this.Worker.findAll({ include: [ this.Task ] })
) }.bind(this), 'Task is not associated to Worker!')
done() })
})
}.bind(this)) //- setTask it('throws an error if alias is not associated', function() {
}.bind(this)) //- Task.create Helpers.assertException(function() {
}.bind(this)) //- Task.create this.Worker.findAll({ include: [ { daoFactory: this.Task, as: 'Work' } ] })
}.bind(this), 'Task (Work) is not associated to Worker!')
}.bind(this)) //- User.create })
}.bind(this)) //- sequelize.sync
it('returns the associated task via worker.task', function(done) {
this.Worker.findAll({
where: { id: this.worker.id },
include: [ { daoFactory: this.Task, as: 'ToDos' } ]
}).complete(function(err, workers) {
expect(err).toBeNull()
expect(workers).toBeDefined()
expect(workers[0].toDos).toBeDefined()
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: findAll
describe('min', function() { describe('min', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!