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:
Miroslav Bajtoš 2015-02-26 16:29:29 +01:00
parent 19a3fe64e4
commit 610767b6c8
2 changed files with 14 additions and 2 deletions

View File

@ -7,6 +7,7 @@ var registry = require('./registry');
var runtime = require('./runtime'); var runtime = require('./runtime');
var assert = require('assert'); var assert = require('assert');
var async = require('async'); var async = require('async');
var deprecated = require('depd')('loopback');
/** /**
* Extends Model with basic query and CRUD support. * Extends Model with basic query and CRUD support.
@ -1041,6 +1042,15 @@ PersistedModel.enableChangeTracking = function() {
assert(this.dataSource, 'Cannot enableChangeTracking(): ' + this.modelName + assert(this.dataSource, 'Cannot enableChangeTracking(): ' + this.modelName +
' is not attached to a dataSource'); ' 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.attachTo(this.dataSource);
Change.getCheckpointModel().attachTo(this.dataSource); Change.getCheckpointModel().attachTo(this.dataSource);

View File

@ -38,6 +38,7 @@
"canonical-json": "0.0.4", "canonical-json": "0.0.4",
"continuation-local-storage": "~3.1.1", "continuation-local-storage": "~3.1.1",
"debug": "~2.0.0", "debug": "~2.0.0",
"depd": "^1.0.0",
"ejs": "~1.0.0", "ejs": "~1.0.0",
"express": "^4.10.2", "express": "^4.10.2",
"inflection": "~1.4.2", "inflection": "~1.4.2",
@ -52,7 +53,7 @@
"underscore.string": "~2.3.3" "underscore.string": "~2.3.3"
}, },
"peerDependencies": { "peerDependencies": {
"loopback-datasource-juggler": "^2.17.0" "loopback-datasource-juggler": "^2.19.0"
}, },
"devDependencies": { "devDependencies": {
"browserify": "~4.2.3", "browserify": "~4.2.3",
@ -79,7 +80,7 @@
"karma-phantomjs-launcher": "~0.1.4", "karma-phantomjs-launcher": "~0.1.4",
"karma-script-launcher": "~0.1.0", "karma-script-launcher": "~0.1.0",
"loopback-boot": "^1.1.0", "loopback-boot": "^1.1.0",
"loopback-datasource-juggler": "^2.17.0", "loopback-datasource-juggler": "^2.19.0",
"loopback-testing": "~0.2.0", "loopback-testing": "~0.2.0",
"mocha": "~1.21.4", "mocha": "~1.21.4",
"strong-task-emitter": "0.0.x", "strong-task-emitter": "0.0.x",
@ -94,6 +95,7 @@
"./lib/server-app.js": "./lib/browser-express.js", "./lib/server-app.js": "./lib/browser-express.js",
"connect": false, "connect": false,
"nodemailer": false, "nodemailer": false,
"depd": "loopback-datasource-juggler/lib/browser.depd.js",
"bcrypt": false "bcrypt": false
}, },
"license": { "license": {