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 = {
|
var context = {
|
||||||
Model: Model,
|
Model: Model,
|
||||||
data: data,
|
data: data,
|
||||||
|
isNewInstance: info && info.isNewInstance,
|
||||||
hookState: ctx.hookState,
|
hookState: ctx.hookState,
|
||||||
options: options
|
options: options
|
||||||
};
|
};
|
||||||
|
|
|
@ -1722,7 +1722,8 @@ module.exports = function(dataSource, should) {
|
||||||
|
|
||||||
if (dataSource.connector.updateOrCreate) {
|
if (dataSource.connector.updateOrCreate) {
|
||||||
observedContexts.should.eql(aTestModelCtx({
|
observedContexts.should.eql(aTestModelCtx({
|
||||||
data: { id: 'new-id', name: 'a name' }
|
data: { id: 'new-id', name: 'a name' },
|
||||||
|
isNewInstance: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
observedContexts.should.eql(aTestModelCtx({
|
observedContexts.should.eql(aTestModelCtx({
|
||||||
|
@ -1750,7 +1751,8 @@ module.exports = function(dataSource, should) {
|
||||||
data: {
|
data: {
|
||||||
id: existingInstance.id,
|
id: existingInstance.id,
|
||||||
name: 'updated name'
|
name: 'updated name'
|
||||||
}
|
},
|
||||||
|
isNewInstance: false
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
// For Unoptimized connector, the callback function `pushContextAndNext`
|
// For Unoptimized connector, the callback function `pushContextAndNext`
|
||||||
|
|
Loading…
Reference in New Issue