Created
July 23, 2012 17:11
-
-
Save eveiga/3164782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DAOFactory.prototype.get_or_create = function(params, defaults){ | |
var self = this; | |
return new Utils.CustomEventEmitter(function(emitter) { | |
self.find({ where: params }) | |
.success( | |
function(instance){ | |
if (instance === null) { | |
for (var attrname in defaults) { | |
params[attrname] = defaults[attrname]; | |
} | |
self.create(params).success( | |
function(instance) { | |
emitter.emit('success', instance) | |
} | |
) | |
} else { | |
emitter.emit('success', instance) | |
} | |
} | |
); | |
}).run() | |
} |
Yup, this gist is incomplete :P
https://github.com/sdepold/sequelize/pull/225
This is the correct version!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Re-implementing Django's ORM? :P
I'm not really into node but, don't you also have to emit the failures?