Inner Join query in TypeORM

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

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

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top