diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 823c2e5..5aff775 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -301,32 +301,30 @@ AbstractClass.upsert = AbstractClass.updateOrCreate = function upsert(query, dat } var Model = this; - if (query.id) { - if (this.schema.adapter.updateOrCreate) { - var inst = new Model(query); - this.schema.adapter.updateOrCreate(Model.modelName, inst.toObject(), function (err, found) { - var obj; - if (found) { - inst._initProperties(found); - obj = inst; - } else { - obj = null; - } - callback(err, obj); - }); - } else { - this.findById(query.id, function (err, inst) { - if (err) - return callback(err); - if (inst) { - inst.updateAttributes(data, callback); - } else { - data = helpers.merge(data, query); - var obj = new Model(data); - obj.save(data, callback); - } - }); - } + if (this.schema.adapter.updateOrCreate) { + var inst = new Model(query); + this.schema.adapter.updateOrCreate(Model.modelName, inst.toObject(), function (err, found) { + var obj; + if (found) { + inst._initProperties(found); + obj = inst; + } else { + obj = null; + } + callback(err, obj); + }); + } else if (query.id) { + this.findById(query.id, function (err, inst) { + if (err) + return callback(err); + if (inst) { + inst.updateAttributes(data, callback); + } else { + data = helpers.merge(data, query); + var obj = new Model(data); + obj.save(data, callback); + } + }); } else { Model.findOne({ where: query