TypeORM does not update MaterializedPath
Asked Answered
I

1

6

I am trying to update materialized path in SQLite3 database with usage of TypeORM. The table for folders (which I am updating) has both parent and parentId columns. When I update parent column, the parentId column is going to update, but not the mpath column.

I tried using both getRepository() and getTreeRepository() for update.

I am not really sure what else to add, see attached model and update method below.

Model

@Entity()
@Tree('materialized-path')
export class Folder {

  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: 'varchar',
    length: 50
  })
  title: string;

  @TreeParent()
  parent: Folder;

  @TreeChildren()
  children: Folder[];

  @Column({
    nullable: true
  })
  parentId: number;

Update

await connection.getTreeRepository<Folder>(Folder).update(id, {
  parent: await connection.getRepository<Folder>(Folder).findOne(parentId)
});
Improbity answered 20/12, 2019 at 17:14 Comment(6)
Did you ever find a solution?Troxell
Unfortunately, no. I ended up building the tree myself.Improbity
Same for me.materialized child path isn't updated when parent is updatedTread
care to share solution?Kazmirci
Same. We ended up using postgres functions instead.Troxell
May i have a reference where i can look, how to implement materialised path in typeorm, cause in theory we use a path filed which i dont see in codeTrev
S
0

I also tried update function, not working. but save function is ok.

Allows tree entities relations to be updated and deleted via the save function from the Repository.(refer to: https://github.com/typeorm/typeorm/pull/7156)

When you save entities using save it always tries to find an entity in the database with the given entity id (or ids). If id/ids are found then it will update this row in the database. If there is no row with the id/ids, a new row will be inserted.(refer to: https://typeorm.io/#/entities)

Skidproof answered 16/2, 2022 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.