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

Updating parent relation causes duplication of child relations #26

Open
ugened47 opened this issue Jul 8, 2021 · 2 comments
Open

Updating parent relation causes duplication of child relations #26

ugened47 opened this issue Jul 8, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@ugened47
Copy link

ugened47 commented Jul 8, 2021

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

@dziraf dziraf added the bug Something isn't working label Feb 24, 2022
@dziraf
Copy link

dziraf commented Feb 24, 2022

This happens due to eager. I've marked this as a bug since we can probably filter out eager props when saving records

@damian-balas
Copy link

@dziraf I have a simmilar problem related to eager. (typeorm + nestjs)
If I enable eager in the user address, then I can't update the adressId in the user edit page.

image
image

Status is successfull, but the payload looks like this:

address.id: 2
address.street: streeeeet
address.city: cityyyyy
address.postcode: 57-222
addressId: 1

after edit, the address id is still 2.

Is it also related due to the fact that there is something wrong with the eager functionality or should I create a separate issue for this?

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants