Inner Join query in TypeORM

export class KeyService {
  public constructor(
    private readonly keyRepository: Repository<Key>
  ) {}

public fetch(userId: id): Promise<any> {
  return this.keyRepository.createQueryBuilder('key')
    .innerJoinAndMapOne('key.user', User, 'user', ' = user.keyId')
    .where('user.userId = :userId', { userId: 1 }) // or you can change condition to 'key.userId = :userId' because of you have `userId` in Key

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top