Change tracking requires a string id set to GUID
Print a deprecation warning when a persisted model is tracking changes but does not have a client-generated unique string id property (GUID).
This commit is contained in:
parent
19a3fe64e4
commit
610767b6c8
|
@ -7,6 +7,7 @@ var registry = require('./registry');
|
|||
var runtime = require('./runtime');
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
var deprecated = require('depd')('loopback');
|
||||
|
||||
/**
|
||||
* Extends Model with basic query and CRUD support.
|
||||
|
@ -1041,6 +1042,15 @@ PersistedModel.enableChangeTracking = function() {
|
|||
assert(this.dataSource, 'Cannot enableChangeTracking(): ' + this.modelName +
|
||||
' is not attached to a dataSource');
|
||||
|
||||
var idName = this.getIdName();
|
||||
var idProp = this.definition.properties[idName];
|
||||
var idType = idProp && idProp.type;
|
||||
var idDefn = idProp && idProp.defaultFn;
|
||||
if (idType !== String || !(idDefn === 'uuid' || idDefn === 'guid')) {
|
||||
deprecated('The model ' + this.modelName + ' is tracking changes, ' +
|
||||
'which requries a string id with GUID/UUID default value.');
|
||||
}
|
||||
|
||||
Change.attachTo(this.dataSource);
|
||||
Change.getCheckpointModel().attachTo(this.dataSource);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"canonical-json": "0.0.4",
|
||||
"continuation-local-storage": "~3.1.1",
|
||||
"debug": "~2.0.0",
|
||||
"depd": "^1.0.0",
|
||||
"ejs": "~1.0.0",
|
||||
"express": "^4.10.2",
|
||||
"inflection": "~1.4.2",
|
||||
|
@ -52,7 +53,7 @@
|
|||
"underscore.string": "~2.3.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"loopback-datasource-juggler": "^2.17.0"
|
||||
"loopback-datasource-juggler": "^2.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "~4.2.3",
|
||||
|
@ -79,7 +80,7 @@
|
|||
"karma-phantomjs-launcher": "~0.1.4",
|
||||
"karma-script-launcher": "~0.1.0",
|
||||
"loopback-boot": "^1.1.0",
|
||||
"loopback-datasource-juggler": "^2.17.0",
|
||||
"loopback-datasource-juggler": "^2.19.0",
|
||||
"loopback-testing": "~0.2.0",
|
||||
"mocha": "~1.21.4",
|
||||
"strong-task-emitter": "0.0.x",
|
||||
|
@ -94,6 +95,7 @@
|
|||
"./lib/server-app.js": "./lib/browser-express.js",
|
||||
"connect": false,
|
||||
"nodemailer": false,
|
||||
"depd": "loopback-datasource-juggler/lib/browser.depd.js",
|
||||
"bcrypt": false
|
||||
},
|
||||
"license": {
|
||||
|
|
Loading…
Reference in New Issue