Enhance "persist" hook in DAO.updateOrCreate
Report `ctx.isNewInstance` when the connector provides this info.
This commit is contained in:
parent
fd9bef4aa7
commit
e9899a93cf
|
@ -521,6 +521,7 @@ DataAccessObject.updateOrCreate = DataAccessObject.upsert = function upsert(data
|
|||
var context = {
|
||||
Model: Model,
|
||||
data: data,
|
||||
isNewInstance: info && info.isNewInstance,
|
||||
hookState: ctx.hookState,
|
||||
options: options
|
||||
};
|
||||
|
|
|
@ -1722,7 +1722,8 @@ module.exports = function(dataSource, should) {
|
|||
|
||||
if (dataSource.connector.updateOrCreate) {
|
||||
observedContexts.should.eql(aTestModelCtx({
|
||||
data: { id: 'new-id', name: 'a name' }
|
||||
data: { id: 'new-id', name: 'a name' },
|
||||
isNewInstance: true,
|
||||
}));
|
||||
} else {
|
||||
observedContexts.should.eql(aTestModelCtx({
|
||||
|
@ -1750,7 +1751,8 @@ module.exports = function(dataSource, should) {
|
|||
data: {
|
||||
id: existingInstance.id,
|
||||
name: 'updated name'
|
||||
}
|
||||
},
|
||||
isNewInstance: false
|
||||
}));
|
||||
} else {
|
||||
// For Unoptimized connector, the callback function `pushContextAndNext`
|
||||
|
|
Loading…
Reference in New Issue