我有2个表: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。
如何访问那些中间表?