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) {
|
function done(err, data) {
|
||||||
var obj;
|
var obj;
|
||||||
if (data && !(data instanceof Model)) {
|
if (data && !(data instanceof Model)) {
|
||||||
inst._initProperties(data);
|
inst._initProperties(data, { persisted: true });
|
||||||
obj = inst;
|
obj = inst;
|
||||||
} else {
|
} else {
|
||||||
obj = data;
|
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() {
|
describe('findOrCreate', function() {
|
||||||
|
|
Loading…
Reference in New Issue