adminjs-typeorm
adminjs-typeorm copied to clipboard
Updating parent relation causes duplication of child relations
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:
- Documents are duplicated on each parent edit
- References of the old copies are set to null
- Only the last set of copies has reference to parent

This happens due to eager
. I've marked this as a bug
since we can probably filter out eager
props when saving records
@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.
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! :)