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

Commit bae5c971 by Ricardo Graça

Fix issue #447

1 parent fe7703c6
Showing with 22 additions and 6 deletions
......@@ -140,12 +140,13 @@ module.exports = (function() {
}
DAOFactory.prototype.findAll = function(options) {
var hasJoin = false;
var hasJoin = false
var options = Utils._.clone(options)
if ((typeof options === 'object') && (options.hasOwnProperty('include'))) {
var includes = options.include
hasJoin = true;
hasJoin = true
options.include = {}
includes.forEach(function(daoName) {
......@@ -154,10 +155,10 @@ module.exports = (function() {
if (!options.include[daoName]) {
options.include[daoName] = this.getAssociationByAlias(daoName).target
}
}.bind(this));
}.bind(this))
// whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null;
// whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null
}
return this.QueryInterface.select(this, this.tableName, options, { type: 'SELECT', hasJoin: hasJoin })
......@@ -168,7 +169,7 @@ module.exports = (function() {
var optcpy = Utils._.clone(options)
optcpy.attributes = optcpy.attributes || [Utils.addTicks(this.tableName)+".*"]
// whereCollection is used for non-primary key updates
// whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || null;
return this.QueryInterface.select(this, [this.tableName, joinTableName], optcpy, { type: 'SELECT' })
......
......@@ -168,5 +168,20 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
}.bind(this))
}.bind(this))
})
it("can reuse query option objects", function(done) {
this.User.create({ username: 'fnord' }).success(function() {
var query = { where: { username: 'fnord' }}
this.User.findAll(query).success(function(users) {
expect(users[0].username).toEqual('fnord')
this.User.findAll(query).success(function(users) {
expect(users[0].username).toEqual('fnord')
done()
}.bind(this))
}.bind(this))
}.bind(this))
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!