Enhance "persisted" hook in DAO.updateAttributes
Add `isNewInstance:false` to the context reported by DAO.updateAttributes()
This commit is contained in:
parent
2f71622e11
commit
5fdd521985
|
@ -2548,6 +2548,7 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, op
|
||||||
where: byIdQuery(Model, getIdValue(Model, inst)).where,
|
where: byIdQuery(Model, getIdValue(Model, inst)).where,
|
||||||
data: context.data,
|
data: context.data,
|
||||||
currentInstance: inst,
|
currentInstance: inst,
|
||||||
|
isNewInstance: false,
|
||||||
hookState: hookState,
|
hookState: hookState,
|
||||||
options: options
|
options: options
|
||||||
};
|
};
|
||||||
|
|
|
@ -1210,7 +1210,8 @@ module.exports = function(dataSource, should) {
|
||||||
id: existingInstance.id,
|
id: existingInstance.id,
|
||||||
name: 'changed',
|
name: 'changed',
|
||||||
extra: null
|
extra: null
|
||||||
}
|
},
|
||||||
|
isNewInstance: false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -1685,7 +1686,7 @@ module.exports = function(dataSource, should) {
|
||||||
function(err, instance) {
|
function(err, instance) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
observedContexts.should.eql(aTestModelCtx({
|
var expectedContext = aTestModelCtx({
|
||||||
where: { id: existingInstance.id },
|
where: { id: existingInstance.id },
|
||||||
data: {
|
data: {
|
||||||
id: existingInstance.id,
|
id: existingInstance.id,
|
||||||
|
@ -1696,7 +1697,15 @@ module.exports = function(dataSource, should) {
|
||||||
name: 'updated name',
|
name: 'updated name',
|
||||||
extra: undefined
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue