> ## Content Index
> Fetch the complete content index at: https://www.karls.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# TypeORM Query Nested relations
- URL: https://www.karls.io/typeorm-nested-relationships/
- Published: 2019-01-18T07:03:37.000Z
- Updated: 2025-12-13T10:50:34.000Z
- Author: Karl Scerbiakas
- Tags: NestJS

Sometimes you have a data model where object has a relationship few levels deep. 

For example:

`Person->job->jobType`

It is a style preference, but I like to use TypeORM as active record. So all my entities ussualy extends `BaseEntity`

```
@Entity('Person')
export class Person extends BaseEntity {
	// Entity properties here
}

```

So to reference nested relationships you just have to do:

```
let personsWithJobType = await Person.find({
  where: {
    id: id
  },
  join: {
    alias: "person",
    leftJoinAndSelect: {
      "jobs": "person.jobs",
      "jobType": "jobs.jobType"
    }
  }
})
```

TypeORM can be tricky to get it right. So I hope this helps! 

Have a nice day!