【发布时间】:2019-07-19 02:22:00
【问题描述】:
我有一个角色实体和一个树形结构的路由实体,它们是多对多关系。
现在我想通过 RoleRepository.find({relations: ['routes']}) 检索所有角色,这将按预期加载所有角色数据,但是 routes 道具不会自动加载它的子数据,看起来像:
[{
id: 1,
name: 'route1',
routes: [{
id: 1,
path: '/home'
}]
}]
我已经检查了所有文档,但没有任何线索。
@Entity()
export class Role {
@PrimaryGeneratedColumn()
public id: number
... some other columns
@ManyToMany(type => Route, route => route.roles)
public routes: Route[]
}
@Entity()
@Tree('materialized-path')
export class Route {
@PrimaryGeneratedColumn()
public id: number
@TreeParent()
public parent: Route
@TreeChildren({ cascade: true })
public children: Route[]
@ManyToMany(type => Role, role => role.routes)
@JoinTable()
public roles: Role[]
}
【问题讨论】:
标签: typeorm