'How to Select Some Fields From Relations in Typeorm Relations
I need to Select Some fields from relations in Nest.js TypeOrm . For Example My Entity is :
@Entity()
export class Chat {
@PrimaryGeneratedColumn()
public id: number;
@Column()
public orderId: number;
@Column({ default: ChatStatus.Active })
public status: ChatStatus;
@Column()
public userId: number;
@ManyToOne(() => User, (user) => user.chats, { nullable: true })
@JoinColumn({ name: 'userId' })
public user: User;
}
Any In My Service :
async findAll(dataSearch) {
return await this.chatRepository.find({
relations: ['user'],
});
}
I Want Just Select "name" , "avatar" from user relation but This select all Columns.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
