Skip to content

Commit

Permalink
added basic support for tree tables - closure tables, nested set, mat…
Browse files Browse the repository at this point in the history
…erialized path
  • Loading branch information
Umed Khudoiberdiev committed Dec 17, 2017
1 parent 2fd585f commit 42d6c88
Show file tree
Hide file tree
Showing 39 changed files with 995 additions and 306 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ feel free to ask us and community.
* now relation id can be set directly to relation, e.g. `Post { @ManyToOne(type => Tag) tag: Tag|number }` with `post.tag = 1` usage.
* now you can disable persistence on any relation by setting `@OneToMany(type => Post, post => tag, { persistence: false })`. This can dramatically improve entity save performance.
* `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`
* lot of changes affect closure table pattern which is planned for fix in 0.3.0
* now `returning` and `output` statements of `InsertQueryBuilder` support array of columns as argument
* 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
* fixed issues with relation updation from one-to-one non-owner side
Expand Down Expand Up @@ -53,6 +52,8 @@ Use `findOne(id)` method instead now.
* `skipSync` in entity options has been renamed to `synchronize`. Now if it set to false schema synchronization for the entity will be disabled.
By default its true.
* now array initializations for relations are forbidden and ORM throws an error if there are entities with initialized relation arrays.
* `@ClosureEntity` decorator has been removed. Instead `@Entity` + `@Tree("closure-table")` must be used
* added support for nested set and materialized path tree hierarchy patterns

## 0.1.10

Expand Down
2 changes: 1 addition & 1 deletion docs/decorator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,6 @@ Learn more about [custom entity repositories](working-with-entity-manager.md).
----
Note: some decorators (like `@ClosureEntity`, `@SingleEntityChild`, `@ClassEntityChild`, `@DiscriminatorColumn`, etc.) aren't
Note: some decorators (like `@Tree`, `@ChildEntity`, etc.) aren't
documented in this reference because they are treated as experimental at the moment.
Expect to see their documentation in the future.
5 changes: 3 additions & 2 deletions docs/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,10 @@ To learn more about closure table take a look at [this awesome presentation by B
Example:

```typescript
import {ClosureEntity, Column, PrimaryGeneratedColumn, TreeChildren, TreeParent, TreeLevelColumn} from "typeorm";
import {Entity, Tree, Column, PrimaryGeneratedColumn, TreeChildren, TreeParent, TreeLevelColumn} from "typeorm";

@ClosureEntity()
@Entity()
@Tree("closure-table")
export class Category {

@PrimaryGeneratedColumn()
Expand Down
73 changes: 1 addition & 72 deletions docs/repository-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,78 +204,7 @@ await repository.clear();

## `TreeRepository` API

* `findTrees` - Gets complete tree for all roots in the table.

```typescript
const treeCategories = await repository.findTrees();
// returns root categories with sub categories inside
```

* `findRoots` - Roots are entities that have no ancestors. Finds them all.
Does not load children leafs.

```typescript
const rootCategories = await repository.findRoots();
// returns root categories without sub categories inside
```

* `findDescendants` - Gets all children (descendants) of the given entity. Returns them all in a flat array.

```typescript
const childrens = await repository.findDescendants(parentCategory);
// returns all direct subcategories (without its nested categories) of a parentCategory
```

* `findDescendantsTree` - Gets all children (descendants) of the given entity. Returns them in a tree - nested into each other.

```typescript
const childrensTree = await repository.findDescendantsTree(parentCategory);
// returns all direct subcategories (with its nested categories) of a parentCategory
```

* `createDescendantsQueryBuilder` - Creates a query builder used to get descendants of the entities in a tree.

```typescript
const childrens = await repository
.createDescendantsQueryBuilder("category", "categoryClosure", parentCategory)
.andWhere("category.type = 'secondary'")
.getMany();
```

* `countDescendants` - Gets number of descendants of the entity.

```typescript
const childrenCount = await repository.countDescendants(parentCategory);
```

* `findAncestors` - Gets all parent (ancestors) of the given entity. Returns them all in a flat array.

```typescript
const parents = await repository.findAncestors(childCategory);
// returns all direct childCategory's parent categories (without "parent of parents")
```

* `findAncestorsTree` - Gets all parent (ancestors) of the given entity. Returns them in a tree - nested into each other.

```typescript
const parentsTree = await repository.findAncestorsTree(childCategory);
// returns all direct childCategory's parent categories (with "parent of parents")
```

* `createAncestorsQueryBuilder` - Creates a query builder used to get ancestors of the entities in a tree.

```typescript
const parents = await repository
.createAncestorsQueryBuilder("category", "categoryClosure", childCategory)
.andWhere("category.type = 'secondary'")
.getMany();
```

* `countAncestors` - Gets the number of ancestors of the entity.

```typescript
const parentsCount = await repository.countAncestors(childCategory);
```
For `TreeRepository` API refer to [the Tree Entities documentation](./tree-entities.md#working-with-tree-entities).

## `MongoRepository` API

Expand Down
15 changes: 6 additions & 9 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ See what amazing new features we are expecting to land in the next TypeORM versi

## Note on 1.0.0 release

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

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

## 0.3.0

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

## 0.2.0

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

0 comments on commit 42d6c88

Please sign in to comment.