Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么 onetomany manytoone 无效 #166

Open
aronsoyol opened this issue Feb 24, 2024 · 1 comment
Open

为什么 onetomany manytoone 无效 #166

aronsoyol opened this issue Feb 24, 2024 · 1 comment

Comments

@aronsoyol
Copy link

aronsoyol commented Feb 24, 2024

使用cooladmin

创建两个实体

主表


@Entity('animal_mymodel')
export class AnimalMymodelEntity   {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ comment: '描述' })
  desc: string;
  
  @OneToMany(() => AnimalMymodelextEntity, ext => ext.model)
  public exts: AnimalMymodelextEntity[];

  @Column({ comment: '创建时间' , nullable: true})
  createTime: Date;
}

从表

@Entity('animal_mymodelext')
export class AnimalMymodelextEntity {

  @PrimaryGeneratedColumn()
    id: number;

  @Column({ comment: '描述' })
  xxx: string;

  @ManyToOne(()=> AnimalMymodelEntity, mymodel => mymodel.exts)
  @JoinColumn()
  model: AnimalMymodelEntity;
}

主表的为AnimalMymodelEntity实体类里为什么没有exts字段?

image

image

数据表

主表

image

从表

image

@cool-team-official
Copy link
Owner

不要用外键

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants