From e9899a93cf3bbb95f99298da238d78d30a9cf992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 18 Dec 2015 16:06:53 +0100 Subject: [PATCH] Enhance "persist" hook in DAO.updateOrCreate Report `ctx.isNewInstance` when the connector provides this info. --- lib/dao.js | 1 + test/persistence-hooks.suite.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 827cdd3e..70355dee 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -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 }; diff --git a/test/persistence-hooks.suite.js b/test/persistence-hooks.suite.js index 897933d0..050a7fa2 100644 --- a/test/persistence-hooks.suite.js +++ b/test/persistence-hooks.suite.js @@ -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`