@Crud({
model: {
type: Gate,
},
})
@ApiUseTags('Gate')
@Controller('gate')
export class GateController {
constructor(public service: GateService) {
}
}
@Injectable()
export class GateService extends TypeOrmCrudService<Gate> {
constructor(@InjectRepository(Gate) repo) {
super(repo);
}
}
@Entity()
export class Gate {
@ApiModelProperty()
@PrimaryGeneratedColumn()
id: number;
@ApiModelProperty()
@Column()
name: string;
@ManyToOne(type => School, school => school.gates, {
eager: true,
})
@JoinColumn({ name: 'school_id' })
school: School;
}
How to get out put as a eager.
Yo! Thanks for the question!
You can load eager relations like so
@Crud({
model: {
type: Gate,
},
query: {
joins: {
school: {
eager: true,
},
},
},
})
@Crud({ model: { type: Gate, }, query: { joins: { school: { eager: true, }, }, }, })Thank you for the help! It works.
Another problem is, how to give swagger support for this. its show sample output as like =>
[ { "id": 0, "title": "string", } ]
And eager between 3 relational classes not load.
typeorm is going to deprecate eager and lazy loading
see https://github.com/typeorm/typeorm/issues/3251