Fix PersistedModel._defineChangeModel
Correctly handle the case when the model is attached multiple times during the lifecycle, this happens because `loopback.createModel` always makes an attempt to auto-attach.
This commit is contained in:
parent
b18d2516a4
commit
28acffd7dd
|
@ -1423,10 +1423,15 @@ module.exports = function(registry) {
|
||||||
|
|
||||||
if (this.dataSource) {
|
if (this.dataSource) {
|
||||||
attachRelatedModels(this);
|
attachRelatedModels(this);
|
||||||
} else {
|
|
||||||
this.once('dataSourceAttached', attachRelatedModels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We have to attach related model whenever the datasource changes,
|
||||||
|
// this is a workaround for autoAttach called by loopback.createModel
|
||||||
|
var self = this;
|
||||||
|
this.on('dataSourceAttached', function() {
|
||||||
|
attachRelatedModels(self);
|
||||||
|
});
|
||||||
|
|
||||||
return this.Change;
|
return this.Change;
|
||||||
|
|
||||||
function attachRelatedModels(self) {
|
function attachRelatedModels(self) {
|
||||||
|
|
Loading…
Reference in New Issue