typeorm 复合主键
2020-06-18 本文已影响0人
此昵称已被狗抢占
https://github.com/typeorm/typeorm/issues/3657
import { Entity, PrimaryColumn, Column, ManyToOne, JoinColumn, Index } from "typeorm";
import { Role } from './Role';
import { Permission } from './Permission';
@Entity()
export class RolePermission {
@PrimaryColumn({ name: 'role_id' })
roleId?: number;
@PrimaryColumn({ name: 'permission_id' })
permissionId?: number;
@ManyToOne(type => Role, role => role.rolePermissions)
@JoinColumn({ name: "role_id", referencedColumnName: "id" })
role: Role;
@ManyToOne(type => Permission, Permission => Permission.rolePermissions)
@JoinColumn({ name: "permission_id", referencedColumnName: "id" })
permission: Permission;
}