Throw Error for property names with dots

Result of Compat Flags Clenup.
Throws an error for property names with dots, instead
of a deprecation warning.
This commit is contained in:
gunjpan 2016-05-26 17:21:37 -04:00
parent 366e93f50b
commit 8117b0403f
4 changed files with 28 additions and 24 deletions

View File

@ -75,3 +75,11 @@ Model events
See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/965)
for more details.
## Model property names with dot(s) generates an error
Instead of showing a deprecation warning for model property names with dots,
for example, `customer.name: 'string'`, an error is thrown in 3.0 for
enforcing use of valid model property names.
See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/947) for more details.

View File

@ -246,9 +246,9 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
delete properties[p];
}
// Warn about properties with unsupported names
// Throw error for properties with unsupported names
if (/\./.test(p)) {
deprecated('Property names containing a dot are not supported. ' +
throw new Error('Property names containing dot(s) are not supported. ' +
'Model: ' + className + ', property: ' + p);
}

View File

@ -232,11 +232,12 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
self[p] = self.__data[p] =
(propVal !== undefined) ? propVal : self.__cachedRelations[p];
// Warn about properties with unsupported names
// Throw error for properties with unsupported names
if (/\./.test(p)) {
deprecated('Property names containing a dot are not supported. ' +
'Model: ' + this.constructor.modelName +
', dynamic property: ' + p);
throw new Error(
'Property names containing dot(s) are not supported. ' +
'Model: ' + this.constructor.modelName + ', dynamic property: ' +
p);
}
} else if (strict === 'throw') {
throw new Error('Unknown property: ' + p);

View File

@ -375,13 +375,10 @@ describe('ModelDefinition class', function() {
});
});
it('should report deprecation warning for property names containing dot', function() {
var message = 'deprecation not reported';
process.once('deprecation', function(err) { message = err.message; });
memory.createModel('Dotted', { 'dot.name': String });
message.should.match(/Dotted.*dot\.name/);
it('should throw error for property names containing dot', function() {
(function() { memory.createModel('Dotted', { 'dot.name': String }); })
.should
.throw(/dot\(s\).*Dotted.*dot\.name/);
});
it('should report deprecation warning for property named constructor', function() {
@ -393,14 +390,12 @@ describe('ModelDefinition class', function() {
message.should.match(/Property name should not be "constructor" in Model: Ctor/);
});
it('should report deprecation warning for dynamic property names containing dot', function(done) {
var message = 'deprecation not reported';
process.once('deprecation', function(err) { message = err.message; });
it('should throw error for dynamic property names containing dot',
function(done) {
var Model = memory.createModel('DynamicDotted');
Model.create({ 'dot.name': 'dot.value' }, function(err) {
if (err) return done(err);
message.should.match(/Dotted.*dot\.name/);
err.should.be.instanceOf(Error);
err.message.should.match(/dot\(s\).*DynamicDotted.*dot\.name/);
done();
});
});