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') {
|
||||
var baseName = BaseModel;
|
||||
BaseModel = this.getModel(BaseModel);
|
||||
|
||||
if (BaseModel === undefined) {
|
||||
console.warn('Model `%s` is extending an unknown model `%s`. ' +
|
||||
'Using `PersistedModel` as the base.', name, baseName);
|
||||
BaseModel = this.findModel(BaseModel);
|
||||
if (!BaseModel) {
|
||||
throw new Error('Model not found: model `' + name + '` is extending an unknown model `' +
|
||||
baseName + '`.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,16 @@
|
|||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
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() {
|
||||
it('should allow two apps to reuse the same model name', function(done) {
|
||||
var appFoo = loopback();
|
||||
|
|
Loading…
Reference in New Issue