Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject Tree Typeorm Repository in Nestjs

is it possible to inject Tree Typeorm repository into Nestjs?

I didn't find anything online or in the sources that would help me here.

Or would it be better at this point to initialize nestjs and Typeorm seperat and not use the injection of nestjs and the TypeOrm module of Nestjs?

like image 803
circy Avatar asked Dec 29 '25 04:12

circy


2 Answers

You can also do:

  constructor(@InjectRepository(Entity)
              private readonly treeRepository: TreeRepository<Entity>,
              ) {
  }

  async findAllNested(): Promise<Entity[]> {
    return await this.treeRepository.findTrees();
  }
like image 123
Ambroise Rabier Avatar answered Dec 31 '25 19:12

Ambroise Rabier


I found the solution myself right after I posted this. :D You just have to inject the EntityManager with @InjectEntityManager() and then you can access .getTreeRepository().

like image 25
circy Avatar answered Dec 31 '25 17:12

circy