Now when you load questions you don't need to join or specify relations you want to load. They will be loaded automatically:
constquestionRepository=dataSource.getRepository(Question)// questions will be loaded with its categoriesconstquestions=awaitquestionRepository.find()
Eager relations only work when you use find* methods. If you use QueryBuilder eager relations are disabled and have to use leftJoinAndSelect to load the relation. Eager relations can only be used on one side of the relationship, using eager: true on both sides of relationship is disallowed.
Lazy relations
Entities in lazy relations are loaded once you access them. Such relations must have Promise as type - you store your value in a promise, and when you load them a promise is returned as well. Example:
Example how to load objects inside lazy relations:
const [question] =awaitdataSource.getRepository(Question).find()constcategories=awaitquestion.categories// you'll have all question's categories inside "categories" variable now
Note: if you came from other languages (Java, PHP, etc.) and are used to use lazy relations everywhere - be careful. Those languages aren't asynchronous and lazy loading is achieved different way, that's why you don't work with promises there. In JavaScript and Node.JS you have to use promises if you want to have lazy-loaded relations. This is non-standard technique and considered experimental in TypeORM.