typeorm请求自动生成表nestjs

093gszye  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(623)

我有两张table: teams 以及 users 有两个中间表,由typeorm自动生成。
以下是mysqlworkbench中的表的外观:

下面是实体的片段。

用户.实体

import { Teams } from './teams.entity';
import { Feedbacklog } from './feedbacklog.entity';
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToMany, ManyToOne } from 'typeorm';

@Entity({
    name: 'users',
})
export class Users {

    @PrimaryGeneratedColumn({
        name: 'userID',
    })
    userID: number;

    @Column('varchar', {
        nullable: false,

        length: 100,
        name: 'email',
    })
    email: string;

    @Column('varchar', {
        nullable: false,

        length: 200,
        name: 'password',
    })
    password: string;

    @Column('varchar', {
        nullable: false,
        length: 20,
        unique: true,

        name: 'username',
    })
    username: string;

    @Column('varchar', {
        nullable: false,
        length: 35,

        name: 'firstName',
    })
    firstName: string;

    @Column('varchar', {
        nullable: true,
        length: 35,

        name: 'lastName',
    })
    lastName: string | null;

    @Column('int', {
        nullable: false,
        default: 0,

        name: 'receivedFeedbacks',
    })
    receivedFeedbacks: number;

    @Column('int', {
        nullable: false,
        default: 0,

        name: 'givenFeedbacks',
    })
    givenFeedbacks: number;

    @Column('varchar', {
        nullable: false,
        length: 20,
        default: 'User',

        name: 'role',
    })
    role: string;

    @ManyToMany(type => Teams, team => team.user)
    team: Teams[];
    @OneToMany(type => Feedbacklog, feedbacklog => feedbacklog.receiver, { eager: true })
    received: Feedbacklog[];

    @OneToMany(type => Feedbacklog, feedbacklog => feedbacklog.sender, { eager: true })
    sent: Feedbacklog[];
}

团队.实体

import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToMany, JoinTable } from 'typeorm';
import { Users } from './users.entity';
@Entity({
    name: 'teams'
    ,
})
export class Teams {

    @PrimaryGeneratedColumn({
        name: 'teamID',
    })
    teamID: number;

    @Column('varchar', {
        nullable: false,
        length: 40,

        name: 'projectName',
    })
    projectName: string;

    @Column('date', {
        nullable: false,

        name: 'startDate',
    })
    startDate: string;

    @Column('date', {
        nullable: false,

        name: 'endDate',
    })
    endDate: string;

    @Column('int', {
        nullable: false,

        name: 'teamMembers',
    })
    teamMembers: number;

    @ManyToMany(type => Users, {
        eager: true,
    })
    @JoinTable()
    user: Users[];

    @ManyToMany(type => Users)
    @JoinTable()
    teamLead: Users[];
}

我用的是nestjs,数据库是mariadb。
我怎样才能进入那些中间的table?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题