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

Commit 9e0c5b14 by Elliot Foster

findOrCreate does not modify inputs

This helps when making spy assertions about what arguments findOrCreate
was called with.
1 parent d5c66c39
Showing with 8 additions and 3 deletions
......@@ -567,16 +567,21 @@ module.exports = (function() {
DAOFactory.prototype.findOrCreate = function (params, defaults) {
var self = this;
var where = {};
for (var attrname in params) {
where[attrname] = params[attrname]
}
return new Utils.CustomEventEmitter(function (emitter) {
self.find({
where: params
where: where
}).success(function (instance) {
if (instance === null) {
for (var attrname in defaults) {
params[attrname] = defaults[attrname]
where[attrname] = defaults[attrname]
}
self.create(params)
self.create(where)
.success(function (instance) {
emitter.emit('success', instance, true)
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!