Skip to content

Updating parent relation causes duplication of child relations #26

Open
@ugened47

Description

@ugened47

With the new versions of adminjs and adminjs-typeorm I see that child relation is duplicated when I'm editing the parent.

Here are my entities:

@Entity()
class Bill extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column('text', { nullable: true })
  content: string;

  @Column('jsonb', { nullable: true })
  contentJson: string;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @OneToMany(() => Document, (document) => document.bill, {
    cascade: true,
    eager: true,
  })
  documents: Document[];

  @OneToOne(() => Proposable, { nullable: true, onDelete: 'SET NULL' })
  @JoinColumn()
  proposable?: Proposable;
}


@Entity()
class Document extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column('text')
  content: string;

  @Column('jsonb', { nullable: true })
  contentJson: string;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @ManyToOne(() => Bill, (bill) => bill.documents, { onDelete: 'CASCADE' })
  bill: Bill;

  @RelationId((document: Document) => document.bill)
  billId: number;

  @OneToOne(() => Proposable, { nullable: true, onDelete: 'SET NULL' })
  @JoinColumn()
  proposable?: Proposable;
}

Once editing Bill entity with adminjs I see next:

  1. Documents are duplicated on each parent edit
  2. References of the old copies are set to null
  3. Only the last set of copies has reference to parent

Screenshot 2021-07-08 at 21 33 45

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions