You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reproduce this with the loopback-example app:
Modify 'car.json' to have many notes
{
"name": "Car",
[ ... all other stuff stays the same ... ]
"relations": {
"notes": {
"type": "hasMany",
"model": "Note",
"foreignKey": "carId"
},
},
[ ... all other stuff stays the same ... ]
}
and the Note model to belong to a car
{
"name": "Note",
[ ... all other stuff stays the same ... ]
"relations": {
"car":{
"type": "belongsTo",
"model": "Car",
"foreignKey": "carId"
}
},
[ ... all other stuff stays the same ... ]
}
Add or change car.js to inspect the prototype to see that the hasMany relation fails, see the lack of get__Notes, create__Notes, delete__Notes
module.exports = function(Car){
Car.on('dataSourceAttached', function (attachedCar) {
console.log(attachedCar.prototype);
});
};
and (to show that belongsTo works) inspect the Note.js:
module.exports = function(Note){
Note.on('dataSourceAttached', function (attachedNote) {
console.log(attachedNote.prototype);
});
};
Please note that loopback also uses dataSourceAttached event to set up the relations. Maybe your listener is called before the loopback internal ones. Can you check with the api explorer?
Perhaps the 'everythingIsAttachedNowYouCanStartDisablingYourMethods' event should be emitted seperately ... and it should be not so long like my proposal 😃
You mean dataSouceAttaching during the and a dataSourceAttached after the final attachment ?
Sound good, but what for is the dataSourceAttaching needed ?
But why does this only occur on hasMany relations? If its a race condition of injecting relation methods then it should happen with the other relations as well.
Activity
raymondfeng commentedon Jul 31, 2014
Please note that loopback also uses
dataSourceAttachedevent to set up the relations. Maybe your listener is called before the loopback internal ones. Can you check with the api explorer?nvdnkpr commentedon Jul 31, 2014
They relation works in the explorer. Looks like a race condition of listeners, does it ?
nvdnkpr commentedon Jul 31, 2014
Perhaps the 'everythingIsAttachedNowYouCanStartDisablingYourMethods' event should be emitted seperately ... and it should be not so long like my proposal 😃
raymondfeng commentedon Jul 31, 2014
Maybe another event makes sense, for example, dataSourceAttaching and dataSourceAttached.
nvdnkpr commentedon Jul 31, 2014
You mean
dataSouceAttachingduring the and adataSourceAttachedafter the final attachment ?Sound good, but what for is the
dataSourceAttachingneeded ?raymondfeng commentedon Jul 31, 2014
dataSourceAttaching will be used by loopback to inject the relation methods
nvdnkpr commentedon Jul 31, 2014
But why does this only occur on
hasManyrelations? If its a race condition of injecting relation methods then it should happen with the other relations as well.raymondfeng commentedon Aug 4, 2014
It should have been fixed now as loopback internally uses a different event to finish the relation set up.
nvdnkpr commentedon Aug 4, 2014
👍 will it be in the next version ?
raymondfeng commentedon Aug 4, 2014
loopbackio/loopback-datasource-juggler#200
I thought it was merged and released, but that hasn't happened yet :-)