Skip to content

Commit

Permalink
Fix findOne/0
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Jul 24, 2016
1 parent 53d57f7 commit 62eb1e8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/model.js
Expand Up @@ -380,20 +380,26 @@ AbstractClass.findOrCreate = function findOrCreate(query, data, callback) {
if (typeof query === 'undefined') {
query = {where: {}};
}

if (typeof data === 'function' || typeof data === 'undefined') {
callback = data;
data = query && query.where;
}
if (typeof callback === 'undefined') {
callback = function() {};

if (typeof query === 'function') {
callback = query;
query = { where: {} };
}

var t = this;
this.findOne(query, function(err, record) {
if (err) return callback(err);
if (record) return callback(null, record);
t.create(data, callback);
});
this.findOne(query)
.then(function(record) {
if (record) {
return callback(null, record);
}
t.create(data, callback);
})
.catch(callback);
};

/**
Expand Down

0 comments on commit 62eb1e8

Please sign in to comment.