Tree closure table is not updated on parent update
See original GitHub issueIssue 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:
- Created 5 years ago
- Reactions:26
- Comments:19 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/typeorm/typeorm/blob/c654d5228ccdd867557cf0754e13d47cc2211186/src/repository/TreeRepository.ts#L13
I guess ability to change parent hasn’t been implemented yet.
I think this should be explicitly pointed out in the document.