Enhance "persist" hook in DAO.updateOrCreate

Report `ctx.isNewInstance` when the connector provides this info.
This commit is contained in:
Miroslav Bajtoš 2015-12-18 16:06:53 +01:00
parent fd9bef4aa7
commit e9899a93cf
2 changed files with 5 additions and 2 deletions

View File

@ -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
};

View File

@ -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`