Closed yannbriancon closed 1 year ago
@koskimas I traced the condition !(models[0] instanceof modelClass)
back to the initial commit of the library in the file MoronQueryBuilder.js.
function eagerFetch(builder, models) {
if (models instanceof builder._modelClass || (_.isArray(models) && models[0] instanceof builder._modelClass)) {
return builder._modelClass.loadRelated(models, builder._eagerExpression, builder._allowedExpression);
} else {
return models;
}
}
Do you remember why it is needed?
Anyone has any lead on this? @koskimas
Objectionjs version: 3.0.1
I am referencing the same table in several models and followed the resolution of the issue #1674.
This comment from @koskimas looked exactly like what I needed to have a generic model and fetch specific models from it.
It works perfectly except when I add a relation to the Message model.
Then the query
Post.query().select().withGraphFetched('user')
returns a Message with the fielduser: undefined
. Though, the queryMessage.query().select().withGraphFetched('user')
returns the Message with the field user filled.I manage to track down the issue to the method
onAfter2
in WhereInEagerOperation.js.The check
!(models[0] instanceof modelClass)
below return false because Message is not an instance of Post. So the relations are not fetched.I would like to have your opinion on this issue to see if we should consider it as a bug or propose a workaround.
Thank you in advance for your help ;)