例如:
3 tables
user
user_business_lines_business_line
business_line
那些创建者typeorm
与声明User
@ManyToMany(type => BusinessLine)
@JoinTable()
businessLines: BusinessLine[]
然后,如何添加列字段,例如
@CreateDateColumn({ type: 'timestamp' })
createdAt: Date
@UpdateDateColumn({ type: 'timestamp' })
updatedAt: Date
to user_business_lines_business_line
无法在自动创建的多对多桥接表中添加自定义列。因此,创建另一个表并给出它们之间的一对多和多对一关系。
例如:
三桌
用户 -> 表 1
业务线 -> 表 2
用户业务线-> User 表和 BusinessLine 表之间的桥接表
UserBusinessLine table will contain the foreign key of both parent tables and also we can add custom columns into it.
在用户表中
@OneToMany(() => UserBusinessLine, (userBusinessLine) => userBusinessLine.user)
public userBusinessLines: UserBusinessLine[];
在业务线表中
@OneToMany(() => UserBusinessLine, (userBusinessLine) => userBusinessLine.businessLine)
public userBusinessLines: UserBusinessLine[];
在 UserBusinessLine 表中
@ManyToOne(() => User, (user) => user.userBusinessLines)
public user: User;
@ManyToOne(() => BusinessLine, (businessLine) => businessLine.userBusinessLines)
public businessLine: BusinessLine;
// Custom Colums
@CreateDateColumn({ type: 'timestamp' })
createdAt: Date;
@UpdateDateColumn({ type: 'timestamp' })
updatedAt: Date;
所以现在自定义表有User表和BusinessLine表的外键。还有 CreateddateColumn 和 UpdatedDateColumn
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)