Add TreeModel and HasSubtree implementation

This commit is contained in:
2022-08-20 16:21:06 -05:00
parent 3d836afa59
commit f63891ef99
22 changed files with 380 additions and 108 deletions

View File

@@ -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)