Add TreeModel and HasSubtree implementation
This commit is contained in:
@@ -70,6 +70,11 @@ export class ModelResultIterable<T extends Model<T>> extends AbstractResultItera
|
||||
* @protected
|
||||
*/
|
||||
protected async processEagerLoads(results: Collection<T>): Promise<void> {
|
||||
if ( results.isEmpty() ) {
|
||||
// Nothing to load relations for, so no reason to perform more queries
|
||||
return
|
||||
}
|
||||
|
||||
const eagers = this.builder.getEagerLoadedRelations()
|
||||
const model = this.make<T>(this.ModelClass)
|
||||
|
||||
@@ -78,9 +83,10 @@ export class ModelResultIterable<T extends Model<T>> extends AbstractResultItera
|
||||
|
||||
const relation = model.getRelation(name)
|
||||
const select = relation.buildEagerQuery(this.builder, results)
|
||||
const resultCount = await select.get().count()
|
||||
|
||||
const allRelated = await select.get().collect()
|
||||
allRelated.each(result => {
|
||||
const allRelated = resultCount ? await select.get().collect() : collect()
|
||||
results.each(result => {
|
||||
const resultRelation = result.getRelation(name as any)
|
||||
const resultRelated = resultRelation.matchResults(allRelated as any)
|
||||
resultRelation.setValue(resultRelated as any)
|
||||
|
||||
Reference in New Issue
Block a user