feat: remove a Model from all registries
Add API allowing consumers (e.g. LoopBack) to remove a Model from all juggler registries: - ModelBuilder's models - ModelBuilder's definitions - Connector registry of models
This commit is contained in:
parent
01427b1755
commit
5af4c42728
|
@ -800,6 +800,16 @@ DataSource.prototype.define = function defineClass(className, properties, settin
|
|||
return modelClass;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a model from the registry.
|
||||
*
|
||||
* @param {String} modelName
|
||||
*/
|
||||
DataSource.prototype.deleteModelByName = function(modelName) {
|
||||
this.modelBuilder.deleteModelByName(modelName);
|
||||
delete this.connector._models[modelName];
|
||||
};
|
||||
|
||||
/**
|
||||
* Mixin DataAccessObject methods.
|
||||
*
|
||||
|
|
|
@ -806,6 +806,16 @@ ModelBuilder.prototype.copyModel = function copyModel(Master) {
|
|||
return Slave;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a model from the registry.
|
||||
*
|
||||
* @param {String} modelName
|
||||
*/
|
||||
ModelBuilder.prototype.deleteModelByName = function(modelName) {
|
||||
delete this.models[modelName];
|
||||
delete this.definitions[modelName];
|
||||
};
|
||||
|
||||
/*!
|
||||
* Define hidden property
|
||||
*/
|
||||
|
|
|
@ -154,4 +154,36 @@ describe('DataSource', function() {
|
|||
dataSource.name.should.equal('myDataSource');
|
||||
dataSource.connector.should.equal(mockConnector);
|
||||
});
|
||||
|
||||
describe('deleteModelByName()', () => {
|
||||
it('removes the model from ModelBuilder registry', () => {
|
||||
const ds = new DataSource('ds', {connector: 'memory'});
|
||||
|
||||
ds.createModel('TestModel');
|
||||
Object.keys(ds.modelBuilder.models)
|
||||
.should.containEql('TestModel');
|
||||
Object.keys(ds.modelBuilder.definitions)
|
||||
.should.containEql('TestModel');
|
||||
|
||||
ds.deleteModelByName('TestModel');
|
||||
|
||||
Object.keys(ds.modelBuilder.models)
|
||||
.should.not.containEql('TestModel');
|
||||
Object.keys(ds.modelBuilder.definitions)
|
||||
.should.not.containEql('TestModel');
|
||||
});
|
||||
|
||||
it('removes the model from connector registry', () => {
|
||||
const ds = new DataSource('ds', {connector: 'memory'});
|
||||
|
||||
ds.createModel('TestModel');
|
||||
Object.keys(ds.connector._models)
|
||||
.should.containEql('TestModel');
|
||||
|
||||
ds.deleteModelByName('TestModel');
|
||||
|
||||
Object.keys(ds.connector._models)
|
||||
.should.not.containEql('TestModel');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue