How to use the @loopback/repository.createHasManyInclusionResolver function in @loopback/repository

To help you get started, we’ve selected a few @loopback/repository examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / packages / repository-tests / src / crud / retrieve-including-relations.suite.ts View on Github external
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {
          categoryRepo = new repositoryClass(Category, ctx.dataSource);
          itemRepo = new repositoryClass(Item, ctx.dataSource);

          if (!hasInclusionResolvers(categoryRepo)) {
            throw new Error(
              `Repository class "${categoryRepo.constructor.name}" must provide a public "inclusionResolvers" property`,
            );
          }

          const itemsMeta = Category.definition.relations.items;
          const itemsResolver = createHasManyInclusionResolver(
            itemsMeta as HasManyDefinition,
            async () => itemRepo,
          );
          categoryRepo.inclusionResolvers.set('items', itemsResolver);

          await ctx.dataSource.automigrate([Category.name, Item.name]);
        }),
      );