【发布时间】:2021-05-19 16:50:48
【问题描述】:
我有两个用 Foalts 框架编写的实体,它们正在使用 Typeorm。
这是user.entity.ts:
@Entity()
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
password: string;
@Column({ unique: true })
phone: string
@OneToOne(() => UserProfile)
@JoinColumn()
userProfile: UserProfile
}
第二个是用户资料:
@Entity()
export class UserProfile extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstname: string;
@Column()
surname: string
@Column()
email: string
@Column()
birthDate: number
}
export { DatabaseSession } from '@foal/typeorm';
我的问题是:如何在我的控制器中编写查询以在输出中有这样的对象:
{
"id":41,
"phone":"+18885555555",
"userProfile" : {
"id": 12,
"firstname": "Pourya",
"surname": "Daneshvar",
"email": "example@example.me",
"birthDate": 1613503707
}
}
这是我的控制器:
@Get('/user/profile')
async getUserProfile(ctx: Context) {
const user = await ...
...
return new HttpResponseOK(user)
}
【问题讨论】:
标签: typescript typeorm