我有两个相关模型:
1.- 角色实体
import { Column, Entity, BaseEntity, OneToMany, PrimaryColumn } from "typeorm";
import { Field, ObjectType } from "type-graphql";
import { UserEntity } from "./user.entity";
@ObjectType()
@Entity({
name: "tb_roles"
})
export class RoleEntity extends BaseEntity {
@Field()
@PrimaryColumn({
name: "id",
type: "character varying",
length: 5
})
id!: string;
@Field()
@Column({
name: "description",
type: "character varying",
nullable: true
})
description!: string
@Field(() => [UserEntity])
@OneToMany(() => UserEntity, user => user.role)
users!: UserEntity[];
}
Run Code Online (Sandbox Code Playgroud)
2.- 用户实体
import {Field, ObjectType} from "type-graphql"; …Run Code Online (Sandbox Code Playgroud)