Skip to content

Instantly share code, notes, and snippets.

@SantoshCode
Created April 16, 2021 12:10
Show Gist options
  • Save SantoshCode/388284631ce5f97921468c528e57b832 to your computer and use it in GitHub Desktop.
Save SantoshCode/388284631ce5f97921468c528e57b832 to your computer and use it in GitHub Desktop.
Typeorm(ORM) querying data with relations

Typeorm Querying data with realtions.

Using Repository

const data = this.userRepository.find({
                    relations: ['photos']
                  })

Using QueryBuilder

import { Connection } from 'typeorm';
import UserEntity from './user.entity.ts';

const data = this.connection
                 .getRepository(UserEntity)
                 .createQueryBuilder('user')
                 .leftJoinAndSelect('user.photos','photos')
                 .getMany()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment