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:
Miroslav Bajtoš 2015-04-08 11:52:58 +02:00
parent b18d2516a4
commit 28acffd7dd
1 changed files with 7 additions and 2 deletions

View File

@ -1423,10 +1423,15 @@ module.exports = function(registry) {
if (this.dataSource) {
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;
function attachRelatedModels(self) {