Skip to content

Commit 42d6c88

Browse files
author
Umed Khudoiberdiev
committed
added basic support for tree tables - closure tables, nested set, materialized path
1 parent 2fd585f commit 42d6c88

39 files changed

+995
-306
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ feel free to ask us and community.
1717
* now relation id can be set directly to relation, e.g. `Post { @ManyToOne(type => Tag) tag: Tag|number }` with `post.tag = 1` usage.
1818
* now you can disable persistence on any relation by setting `@OneToMany(type => Post, post => tag, { persistence: false })`. This can dramatically improve entity save performance.
1919
* `loadAllRelationIds` method of `QueryBuilder` now accepts list of relation paths that needs to be loaded, also `disableMixedMap` option is now by default set to false, but you can enable it via new method parameter `options`
20-
* lot of changes affect closure table pattern which is planned for fix in 0.3.0
2120
* now `returning` and `output` statements of `InsertQueryBuilder` support array of columns as argument
2221
* now when many-to-many and one-to-many relation set to `null` all items from that relation are removed, just like it would be set to empty array
2322
* fixed issues with relation updation from one-to-one non-owner side
@@ -53,6 +52,8 @@ Use `findOne(id)` method instead now.
5352
* `skipSync` in entity options has been renamed to `synchronize`. Now if it set to false schema synchronization for the entity will be disabled.
5453
By default its true.
5554
* now array initializations for relations are forbidden and ORM throws an error if there are entities with initialized relation arrays.
55+
* `@ClosureEntity` decorator has been removed. Instead `@Entity` + `@Tree("closure-table")` must be used
56+
* added support for nested set and materialized path tree hierarchy patterns
5657

5758
## 0.1.10
5859

docs/decorator-reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,6 @@ Learn more about [custom entity repositories](working-with-entity-manager.md).
749749
750750
----
751751
752-
Note: some decorators (like `@ClosureEntity`, `@SingleEntityChild`, `@ClassEntityChild`, `@DiscriminatorColumn`, etc.) aren't
752+
Note: some decorators (like `@Tree`, `@ChildEntity`, etc.) aren't
753753
documented in this reference because they are treated as experimental at the moment.
754754
Expect to see their documentation in the future.

docs/entities.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,10 @@ To learn more about closure table take a look at [this awesome presentation by B
516516
Example:
517517

518518
```typescript
519-
import {ClosureEntity, Column, PrimaryGeneratedColumn, TreeChildren, TreeParent, TreeLevelColumn} from "typeorm";
519+
import {Entity, Tree, Column, PrimaryGeneratedColumn, TreeChildren, TreeParent, TreeLevelColumn} from "typeorm";
520520

521-
@ClosureEntity()
521+
@Entity()
522+
@Tree("closure-table")
522523
export class Category {
523524

524525
@PrimaryGeneratedColumn()

docs/repository-api.md

+1-72
Original file line numberDiff line numberDiff line change
@@ -204,78 +204,7 @@ await repository.clear();
204204

205205
## `TreeRepository` API
206206

207-
* `findTrees` - Gets complete tree for all roots in the table.
208-
209-
```typescript
210-
const treeCategories = await repository.findTrees();
211-
// returns root categories with sub categories inside
212-
```
213-
214-
* `findRoots` - Roots are entities that have no ancestors. Finds them all.
215-
Does not load children leafs.
216-
217-
```typescript
218-
const rootCategories = await repository.findRoots();
219-
// returns root categories without sub categories inside
220-
```
221-
222-
* `findDescendants` - Gets all children (descendants) of the given entity. Returns them all in a flat array.
223-
224-
```typescript
225-
const childrens = await repository.findDescendants(parentCategory);
226-
// returns all direct subcategories (without its nested categories) of a parentCategory
227-
```
228-
229-
* `findDescendantsTree` - Gets all children (descendants) of the given entity. Returns them in a tree - nested into each other.
230-
231-
```typescript
232-
const childrensTree = await repository.findDescendantsTree(parentCategory);
233-
// returns all direct subcategories (with its nested categories) of a parentCategory
234-
```
235-
236-
* `createDescendantsQueryBuilder` - Creates a query builder used to get descendants of the entities in a tree.
237-
238-
```typescript
239-
const childrens = await repository
240-
.createDescendantsQueryBuilder("category", "categoryClosure", parentCategory)
241-
.andWhere("category.type = 'secondary'")
242-
.getMany();
243-
```
244-
245-
* `countDescendants` - Gets number of descendants of the entity.
246-
247-
```typescript
248-
const childrenCount = await repository.countDescendants(parentCategory);
249-
```
250-
251-
* `findAncestors` - Gets all parent (ancestors) of the given entity. Returns them all in a flat array.
252-
253-
```typescript
254-
const parents = await repository.findAncestors(childCategory);
255-
// returns all direct childCategory's parent categories (without "parent of parents")
256-
```
257-
258-
* `findAncestorsTree` - Gets all parent (ancestors) of the given entity. Returns them in a tree - nested into each other.
259-
260-
```typescript
261-
const parentsTree = await repository.findAncestorsTree(childCategory);
262-
// returns all direct childCategory's parent categories (with "parent of parents")
263-
```
264-
265-
* `createAncestorsQueryBuilder` - Creates a query builder used to get ancestors of the entities in a tree.
266-
267-
```typescript
268-
const parents = await repository
269-
.createAncestorsQueryBuilder("category", "categoryClosure", childCategory)
270-
.andWhere("category.type = 'secondary'")
271-
.getMany();
272-
```
273-
274-
* `countAncestors` - Gets the number of ancestors of the entity.
275-
276-
```typescript
277-
const parentsCount = await repository.countAncestors(childCategory);
278-
```
207+
For `TreeRepository` API refer to [the Tree Entities documentation](./tree-entities.md#working-with-tree-entities).
279208

280209
## `MongoRepository` API
281210

docs/roadmap.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ See what amazing new features we are expecting to land in the next TypeORM versi
44

55
## Note on 1.0.0 release
66

7-
We are planning to release a final stable `1.0.0` version somewhere in summer 2018.
7+
We are planning to release a final stable `1.0.0` version in summer 2018.
88
However TypeORM is already actively used in number of big production systems.
9-
Main API is already very stable, there are only few issues currently we have in following areas:
10-
`class and single table inheritance`, `naming strategy`, `subscribers`, `tree tables`.
11-
All issues in those areas are planning to be fixed in next minor versions.
12-
Your donations and contribution play a big role in achieving this goal.
9+
Main API is already very stable.
1310
TypeORM follows a semantic versioning and until `1.0.0` breaking changes may appear in `0.x.x` versions,
1411
however since API is already quite stable we don't expect too much breaking changes.
1512

@@ -23,15 +20,11 @@ npm i typeorm@next
2320

2421
## 0.3.0
2522

26-
- [ ] fix Oracle driver issues and make oracle stable and ready for production use
2723
- [ ] add `@Select` and `@Where` decorators
2824
- [ ] add `addSelectAndMap` functionality to `QueryBuilder`
29-
- [ ] research NativeScript support
3025
- [ ] research internationalization features
31-
- [ ] implement soft deletion
3226
- [ ] research ability to create one-to-many relations without inverse sides
3327
- [ ] research ability to create a single relation with multiple entities at once
34-
- [ ] add more tree-table features: nested set and materialized path; more repository methods
3528
- [ ] cli: create database backup command
3629
- [ ] extend `query` method functionality
3730
- [ ] better support for entity schemas, support inheritance, add xml and yml formats support
@@ -41,6 +34,10 @@ npm i typeorm@next
4134

4235
## 0.2.0
4336

37+
- [ ] research NativeScript support
38+
- [x] implement soft deletion
39+
- [x] add more tree-table features: nested set and materialized path; more repository methods
40+
- [ ] fix Oracle driver issues and make oracle stable and ready for production use
4441
- [ ] implement migrations generator for all drivers
4542
- [ ] create example how to use TypeORM in Electron apps
4643
- [ ] finish naming strategy implementation

0 commit comments

Comments
 (0)