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

Commit a3ca2c22 by Sascha Depold

Merge branch 'ghernandez345-master'

2 parents a8117182 8aa472cf
Showing with 27 additions and 10 deletions
...@@ -130,17 +130,25 @@ module.exports = (function() { ...@@ -130,17 +130,25 @@ module.exports = (function() {
if(typeof options === 'number') { if(typeof options === 'number') {
options = { where: options } options = { where: options }
} else if (Utils._.size(primaryKeys) && Utils.argsArePrimaryKeys(arguments, primaryKeys)) { } else if (Utils._.size(primaryKeys) && Utils.argsArePrimaryKeys(arguments, primaryKeys)) {
var where = {} var where = {}
, self = this , self = this
, keys = Utils._.keys(primaryKeys) , keys = Utils._.keys(primaryKeys)
Utils._.each(arguments, function(arg, i) { Utils._.each(arguments, function(arg, i) {
var key = keys[i] var key = keys[i]
where[key] = arg where[key] = arg
}) })
options = { where: where } options = { where: where }
} else if((typeof options === 'object') && (options.hasOwnProperty('include'))) { } else if ((typeof options === 'string') && (parseInt(options, 10).toString() === options)) {
var parsedId = parseInt(options, 10);
if(!Utils._.isFinite(parsedId)) {
throw new Error('Invalid argument to find(). Must be an id or an options object.')
}
options = { where: parsedId }
} else if ((typeof options === 'object') && (options.hasOwnProperty('include'))) {
var includes = options.include var includes = options.include
hasJoin = true; hasJoin = true;
...@@ -178,7 +186,7 @@ module.exports = (function() { ...@@ -178,7 +186,7 @@ module.exports = (function() {
return this.QueryInterface.rawSelect(this.tableName, options, 'min') return this.QueryInterface.rawSelect(this.tableName, options, 'min')
} }
DAOFactory.prototype.build = function(values, options) { DAOFactory.prototype.build = function(values, options) {
var instance = new DAO(values, Utils._.extend(this.options, { hasPrimaryKeys: this.hasPrimaryKeys, factory: this })) var instance = new DAO(values, Utils._.extend(this.options, { hasPrimaryKeys: this.hasPrimaryKeys, factory: this }))
, self = this , self = this
......
...@@ -300,6 +300,15 @@ describe("[" + dialect.toUpperCase() + "] DAOFactory", function() { ...@@ -300,6 +300,15 @@ describe("[" + dialect.toUpperCase() + "] DAOFactory", function() {
}.bind(this)) }.bind(this))
}) })
it('returns a single dao given a string id', function(done) {
this.User.find(this.user.id + '').success(function(user) {
expect(Array.isArray(user)).toBeFalsy()
expect(user.id).toEqual(this.user.id)
expect(user.id).toEqual(1)
done()
}.bind(this))
})
it("should make aliased attributes available", function(done) { it("should make aliased attributes available", function(done) {
this.User.find({ this.User.find({
where: { id: 1 }, where: { id: 1 },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!