Skip to content

Commit

Permalink
DAO: Fix updateOrCreate to set persisted:true
Browse files Browse the repository at this point in the history
Before this commit, the following code would not work:

    Change.updateOrCreate({...}, function(err, ch) {
      // modify "ch" somewhere later
      ch.save(cb);
    });
  • Loading branch information
Miroslav Bajtoš committed Mar 16, 2015
1 parent 6f771f5 commit 4645614
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dao.js
Expand Up @@ -393,7 +393,7 @@ DataAccessObject.updateOrCreate = DataAccessObject.upsert = function upsert(data
function done(err, data) {
var obj;
if (data && !(data instanceof Model)) {
inst._initProperties(data);
inst._initProperties(data, { persisted: true });
obj = inst;
} else {
obj = data;
Expand Down
9 changes: 9 additions & 0 deletions test/manipulation.test.js
Expand Up @@ -567,6 +567,15 @@ describe('manipulation', function () {
});
});
});

it('should allow save() of the created instance', function(done) {
Person.updateOrCreate(
{ id: 'new-id', name: 'a-name' },
function(err, inst) {
if (err) return done(err);
inst.save(done);
});
});
});

describe('findOrCreate', function() {
Expand Down

0 comments on commit 4645614

Please sign in to comment.