美文网首页
typeorm 复合主键

typeorm 复合主键

作者: 此昵称已被狗抢占 | 来源:发表于2020-06-18 11:01 被阅读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;
    
    }
    
    

    相关文章

      网友评论

          本文标题:typeorm 复合主键

          本文链接:https://www.haomeiwen.com/subject/jrirxktx.html