question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree closure table is not updated on parent update

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [x] sqlite [ ] sqljs [ ] react-native

TypeORM version:

[x] latest [x] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Closure table is not updated when previously created entity updates its parent.

import * as path from 'path';
import { createConnection, ConnectionOptions, getTreeRepository } from 'typeorm';
import { PrimaryGeneratedColumn, Column, Tree, TreeChildren, TreeParent, Entity } from 'typeorm';

@Entity()
@Tree("closure-table")
export class TestEntity {
	@PrimaryGeneratedColumn() id: number;
	@TreeChildren()
	children: TestEntity[];
	@TreeParent() parent: TestEntity;
}

var connectionOptions: ConnectionOptions = {
    type: 'sqlite',
    database: path.join(__dirname, 'test.db'),
    entities: [ TestEntity ],
    synchronize: true,
    logging: true,
    dropSchema: true
};

createConnection(connectionOptions).then(async (c) => {
    var repo = getTreeRepository(TestEntity);
    
    var parent1 = new TestEntity;
    await repo.save(parent1);
    var parent2 = new TestEntity;
    await repo.save(parent2);
    var child = new TestEntity;

    child.parent = parent1;
    await repo.save(child);
    console.log(...await repo.query(`SELECT * FROM ${repo.metadata.closureJunctionTable.name}`));
    
    child.parent = parent2;
    await repo.update(child.id, child);
    console.log(...await repo.query(`SELECT * FROM ${repo.metadata.closureJunctionTable.name}`));
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:26
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
SharmaTusharcommented, May 23, 2018
3reactions
linfan68commented, Oct 2, 2018

I think this should be explicitly pointed out in the document.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to make tree with closure-table in typeorm
Found the answer, in fact it seems that using repository.insert does not properly updates the closure table (supposed to contain identity ...
Read more >
Tree Entities - typeorm - GitBook
TypeORM supports the Adjacency list and Closure table patterns for storing tree structures. To learn more about the hierarchy table take a look...
Read more >
Closure Table v1.1.0 - HexDocs
The Closure Table solution is a simple and elegant way of storing hierarchies. It involves storing all paths through a tree, not just...
Read more >
Closure Tree | closure_tree - GitHub Pages
Closure_tree lets your ActiveRecord models act as nodes in a tree data ... and closure_tree moves the node's descendancy to the new parent...
Read more >
Storing a Tree Structure in a Relational Database - Baeldung
However, inserting and updating nodes into the tree is more complicated. Depending on the depth of the node, we would have to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found