source

테이블 nestj 자동 생성에 대한 TypeORM 요청

gigabyte 2022. 10. 30. 17:53
반응형

테이블 nestj 자동 생성에 대한 TypeORM 요청

테이블이 2개 있습니다.teams그리고.usersType ORM에 의해 자동 생성되는2개의 중앙 테이블이 있습니다.

MySQLWorkbench의 표는 다음과 같습니다.

스크린샷 MySQLWorkbench

여기 엔티티에 대한 단편들이 있습니다.

users.displaces

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[];
}

teams.displays(팀).

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입니다.

저 가운데 테이블은 어떻게 접근할 수 있나요?

언급URL : https://stackoverflow.com/questions/53947971/typeorm-request-to-auto-generated-table-nestjs

반응형