Skip to content

Commit fec7742

Browse files
committed
Add 'isNewInstance' for updateAttributes
* Add 'isNewInstance' to loaded hook for updateAttributes
1 parent 7365e32 commit fec7742

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

lib/dao.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,7 @@ function(data, options, cb) {
30933093
data: context.data,
30943094
hookState: hookState,
30953095
options: options,
3096+
isNewInstance: false,
30963097
};
30973098
Model.notifyObserversOf('loaded', ctx, function(err) {
30983099
if (err) return cb(err);

test/memory.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ describe('Unoptimized connector', function() {
901901
// disable optimized methods
902902
ds.connector.updateOrCreate = false;
903903
ds.connector.findOrCreate = false;
904+
ds.connector.upsertWithWhere = false;
904905

905906
require('./persistence-hooks.suite')(ds, should, {
906907
replaceOrCreateReportsNewInstance: true,

test/persistence-hooks.suite.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
13601360

13611361
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
13621362
data: {name: 'changed'},
1363+
isNewInstance: false,
13631364
}));
13641365

13651366
done();
@@ -2039,25 +2040,13 @@ module.exports = function(dataSource, should, connectorCapabilities) {
20392040
{id: existingInstance.id, name: 'updated name'},
20402041
function(err, instance) {
20412042
if (err) return done(err);
2042-
2043-
if (dataSource.connector.updateOrCreate) {
2044-
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
2045-
data: {
2046-
id: existingInstance.id,
2047-
name: 'updated name',
2048-
},
2049-
isNewInstance: false,
2050-
}));
2051-
} else {
2052-
ctxRecorder.records.should.eql(
2053-
aCtxForModel(TestModel, {
2054-
data: {
2055-
id: existingInstance.id,
2056-
name: 'updated name',
2057-
},
2058-
})
2059-
);
2060-
}
2043+
ctxRecorder.records.should.eql(aCtxForModel(TestModel, {
2044+
data: {
2045+
id: existingInstance.id,
2046+
name: 'updated name',
2047+
},
2048+
isNewInstance: false,
2049+
}));
20612050
done();
20622051
});
20632052
});
@@ -3267,13 +3256,8 @@ module.exports = function(dataSource, should, connectorCapabilities) {
32673256
id: existingInstance.id,
32683257
name: 'updated name',
32693258
},
3259+
isNewInstance: false,
32703260
});
3271-
// For non-atomic implementation of upsertWithWhere on update, it calls
3272-
// updateAttributes. loaded hook of updateAttributes does not provide
3273-
// isNewInstance.
3274-
if (dataSource.connector.upsertWithWhere) {
3275-
expectedContext.isNewInstance = false;
3276-
}
32773261
ctxRecorder.records.should.eql(aCtxForModel(TestModel, expectedContext));
32783262
done();
32793263
});

0 commit comments

Comments
 (0)