Merge pull request #2301 from strongloop/error-extend-unknown-model
Throw descriptive error upon extending unknown model
This commit is contained in:
commit
aa47f79ca6
|
@ -109,11 +109,10 @@ Registry.prototype.createModel = function(name, properties, options) {
|
||||||
|
|
||||||
if (typeof BaseModel === 'string') {
|
if (typeof BaseModel === 'string') {
|
||||||
var baseName = BaseModel;
|
var baseName = BaseModel;
|
||||||
BaseModel = this.getModel(BaseModel);
|
BaseModel = this.findModel(BaseModel);
|
||||||
|
if (!BaseModel) {
|
||||||
if (BaseModel === undefined) {
|
throw new Error('Model not found: model `' + name + '` is extending an unknown model `' +
|
||||||
console.warn('Model `%s` is extending an unknown model `%s`. ' +
|
baseName + '`.');
|
||||||
'Using `PersistedModel` as the base.', name, baseName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,16 @@
|
||||||
// License text available at https://opensource.org/licenses/MIT
|
// License text available at https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
describe('Registry', function() {
|
describe('Registry', function() {
|
||||||
|
describe('createModel', function() {
|
||||||
|
it('should throw error upon extending non-exist base model', function() {
|
||||||
|
var app = loopback();
|
||||||
|
var props = {};
|
||||||
|
var opts = { base: 'nonexistent' };
|
||||||
|
expect(function() { app.registry.createModel('aModel', props, opts); })
|
||||||
|
.to.throw(/model\s`aModel`(.*)unknown\smodel\s`nonexistent`/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('one per app', function() {
|
describe('one per app', function() {
|
||||||
it('should allow two apps to reuse the same model name', function(done) {
|
it('should allow two apps to reuse the same model name', function(done) {
|
||||||
var appFoo = loopback();
|
var appFoo = loopback();
|
||||||
|
|
Loading…
Reference in New Issue