#######################主表
@Entity({ name: 't_class_info' })
export class ClassInfo {
@PrimaryColumn({length:100})
@Generated("uuid")
id: string;
// 使用范围和使用方法
@OneToMany((type) => Person, (person) => person.classInfo, {cascade: true})
persons: Person[];
@Column({length: 100, comment: '班级名称', nullable:true}) //设置默认为null
classname: string;
@Column("text",{comment: '班级描述', nullable:true})
memo: string;
@Column({comment: '创建时间', nullable:true})
createtime: Date;
@Column({comment: '更新时间', nullable:true})
updatetime: Date;
@Column({length: 255, comment: '备用字段1', nullable:true})
reserve1: string;
}
#######################子表
@Entity({ name: 't_person' })
export class Person {
@PrimaryColumn({length:100})
@Generated("uuid")
id: string;
@ManyToOne((type) => ClassInfo, (classInfo) => classInfo.persons)
@JoinColumn({name: 'classid'})
classInfo: ClassInfo;
@Column({length: 255, comment: '名称', nullable:true})
name: string;
@Column({length: 10, comment: '性别', nullable:true})
sex: string;
@Column({length: 255, comment: '含量', nullable:true})
content: string;
@Column({length: 255, comment: '备用字段1', nullable:true})
reserve1: string;
}