Enhance "persisted" hook in DAO.updateAttributes
Add `isNewInstance:false` to the context reported by DAO.updateAttributes()
This commit is contained in:
parent
3028329126
commit
fd9bef4aa7
|
@ -2556,6 +2556,7 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, op
|
|||
where: byIdQuery(Model, getIdValue(Model, inst)).where,
|
||||
data: context.data,
|
||||
currentInstance: inst,
|
||||
isNewInstance: false,
|
||||
hookState: hookState,
|
||||
options: options
|
||||
};
|
||||
|
|
|
@ -1212,7 +1212,8 @@ module.exports = function(dataSource, should) {
|
|||
id: existingInstance.id,
|
||||
name: 'changed',
|
||||
extra: null
|
||||
}
|
||||
},
|
||||
isNewInstance: false
|
||||
}));
|
||||
|
||||
done();
|
||||
|
@ -1687,7 +1688,7 @@ module.exports = function(dataSource, should) {
|
|||
function(err, instance) {
|
||||
if (err) return done(err);
|
||||
|
||||
observedContexts.should.eql(aTestModelCtx({
|
||||
var expectedContext = aTestModelCtx({
|
||||
where: { id: existingInstance.id },
|
||||
data: {
|
||||
id: existingInstance.id,
|
||||
|
@ -1698,7 +1699,15 @@ module.exports = function(dataSource, should) {
|
|||
name: 'updated name',
|
||||
extra: undefined
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
if (!dataSource.connector.updateOrCreate) {
|
||||
// When the connector does not provide updateOrCreate,
|
||||
// DAO falls back to updateAttributes which sets this flag
|
||||
expectedContext.isNewInstance = false;
|
||||
}
|
||||
|
||||
observedContexts.should.eql(expectedContext);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue