DAO: Fix updateOrCreate to set persisted:true
Before this commit, the following code would not work: Change.updateOrCreate({...}, function(err, ch) { // somewhere later, modify "ch" and save the changes ch.save(cb); });
This commit is contained in:
parent
902772f1af
commit
6f11c2d717
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue