Merge pull request #1094 from strongloop/newInstance_loade_updateAttributes
Add 'isNewInstance' for updateAttributes
This commit is contained in:
commit
66f27b9b83
|
@ -3090,6 +3090,7 @@ function(data, options, cb) {
|
||||||
data: context.data,
|
data: context.data,
|
||||||
hookState: hookState,
|
hookState: hookState,
|
||||||
options: options,
|
options: options,
|
||||||
|
isNewInstance: false,
|
||||||
};
|
};
|
||||||
Model.notifyObserversOf('loaded', ctx, function(err) {
|
Model.notifyObserversOf('loaded', ctx, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
|
@ -901,6 +901,7 @@ describe('Unoptimized connector', function() {
|
||||||
// disable optimized methods
|
// disable optimized methods
|
||||||
ds.connector.updateOrCreate = false;
|
ds.connector.updateOrCreate = false;
|
||||||
ds.connector.findOrCreate = false;
|
ds.connector.findOrCreate = false;
|
||||||
|
ds.connector.upsertWithWhere = false;
|
||||||
|
|
||||||
require('./persistence-hooks.suite')(ds, should, {
|
require('./persistence-hooks.suite')(ds, should, {
|
||||||
replaceOrCreateReportsNewInstance: true,
|
replaceOrCreateReportsNewInstance: true,
|
||||||
|
|
|
@ -1360,6 +1360,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
|
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
data: {name: 'changed'},
|
data: {name: 'changed'},
|
||||||
|
isNewInstance: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -2039,25 +2040,13 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
{id: existingInstance.id, name: 'updated name'},
|
{id: existingInstance.id, name: 'updated name'},
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
||||||
if (dataSource.connector.updateOrCreate) {
|
data: {
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
|
id: existingInstance.id,
|
||||||
data: {
|
name: 'updated name',
|
||||||
id: existingInstance.id,
|
},
|
||||||
name: 'updated name',
|
isNewInstance: false,
|
||||||
},
|
}));
|
||||||
isNewInstance: false,
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
ctxRecorder.records.should.eql(
|
|
||||||
aCtxForModel(TestModel, {
|
|
||||||
data: {
|
|
||||||
id: existingInstance.id,
|
|
||||||
name: 'updated name',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3267,13 +3256,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
id: existingInstance.id,
|
id: existingInstance.id,
|
||||||
name: 'updated name',
|
name: 'updated name',
|
||||||
},
|
},
|
||||||
|
isNewInstance: false,
|
||||||
});
|
});
|
||||||
// For non-atomic implementation of upsertWithWhere on update, it calls
|
|
||||||
// updateAttributes. loaded hook of updateAttributes does not provide
|
|
||||||
// isNewInstance.
|
|
||||||
if (dataSource.connector.upsertWithWhere) {
|
|
||||||
expectedContext.isNewInstance = false;
|
|
||||||
}
|
|
||||||
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expectedContext));
|
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expectedContext));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue