changed how cascades should be defined via relation options

This commit is contained in:
Umed Khudoiberdiev 2017-11-20 13:48:14 +05:00
parent 7f2f2e0270
commit 843fbcc886
95 changed files with 163 additions and 315 deletions

View File

@ -7,9 +7,12 @@ feel free to ask us and community.
## 0.2.0 (next: `npm i typeorm@next`)
* completely refactored, improved and optimized persistence process and performance
* completely refactored, improved and optimized persistence process and performance.
* removed cascade remove functionality, refactored how cascades are working.
* removed `cascadeRemove` and `cascadeAll` options from column options.
* removed `cascadeRemove` option from relation options.
* replaced `cascadeAll` with `cascade: true` syntax from relation options.
* replaced `cascadeInsert` with `cascade: ["insert"]` syntax from relation options.
* replaced `cascadeUpdate` with `cascade: ["update"]` syntax from relation options.
* now when one-to-one or many-to-one relation is loaded and its not set (set to null) ORM returns you entity with relation set to `null` instead of `undefined property` as before.
* 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.

View File

@ -697,19 +697,13 @@ export class Photo {
/// ... 其他列
@OneToOne(type => PhotoMetadata, metadata => metadata.photo, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true,
})
metadata: PhotoMetadata;
}
```
* **cascadeInsert** - 如果表中没有关系中的metadata则自动insert即我们不需要再手动insert一个新的photoMetadata对象。
* **cascadeUpdate** - 如果metadata有变化则自动update。
* **cascadeRemove** - 如果把photo里的metadata移除了也就是为空则会自动remove表中的这条metadata数据。
使用cascadeInsert就可以不需要像上面那边先存photo再存metadata了。
使用cascade就可以不需要像上面那边先存photo再存metadata了。
现在我们来单单存photo对象由于cascade的作用metadata也会自动存上。
```typescript
@ -834,9 +828,7 @@ export class Album {
name: string;
@ManyToMany(type => Photo, photo => photo.albums, { // 备注: 会在下面的Photo类里添加"albums"属性
cascadeInsert: true, // 在添加Album时会自动添加相册里的Photo
cascadeUpdate: true, // 在更新Album时会自动更新相册里的Photo
cascadeRemove: true // 在移除Album时会自动移除相册里的Photo
cascade:true
})
@JoinTable()
photos: Photo[];
@ -852,9 +844,7 @@ export class Photo {
/// ... 其他列
@ManyToMany(type => Album, album => album.photos, {
cascadeInsert: true, // 在添加Album时会自动添加相册里的Photo
cascadeUpdate: true, // 在更新Album时会自动更新相册里的Photo
cascadeRemove: true // 在移除Album时会自动移除相册里的Photo
cascade: true
})
albums: Album[];
}

View File

@ -986,20 +986,13 @@ export class Photo {
/// ... other columns
@OneToOne(type => PhotoMetadata, metadata => metadata.photo, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true,
})
metadata: PhotoMetadata;
}
```
* **cascadeInsert** - automatically insert metadata in the relation if it does not exist in its table.
This means that we don't need to manually insert a newly created `photoMetadata` object.
* **cascadeUpdate** - automatically update metadata in the relation if something is changed in this object.
* **cascadeRemove** - automatically remove metadata from its table if you removed metadata from photo object.
Using `cascadeInsert` allows us not to separately save photo and separately save metadata objects now.
Using `cascade` allows us not to separately save photo and separately save metadata objects now.
Now we can simply save a photo object, and the metadata object will be saved automatically because of cascade options.
```typescript
@ -1009,7 +1002,7 @@ createConnection(options).then(async connection => {
let photo = new Photo();
photo.name = "Me and Bears";
photo.description = "I am near polar bears";
photo.filename = "photo-with-bears.jpg"
photo.filename = "photo-with-bears.jpg";
photo.isPublished = true;
// create photo metadata object

View File

@ -21,14 +21,10 @@ There are several types of relations:
There are several options you can specify for relations:
* `eager: boolean` - If set to true, the relation will always be loaded with the main entity when using `find*` methods or `QueryBuilder` on this entity
* `cascadeInsert: boolean` - If set to true, the related object will be inserted into database if it does not exist yet.
* `cascadeUpdate: boolean` - If set to true, the related object will be updated in the database on entity save.
* `cascadeRemove: boolean` - If set to true, the related object will be removed from the database on entity save and without related object.
* `cascadeAll: boolean` - Sets `cascadeInsert`, `cascadeUpdate`, `cascadeRemove` at once.
* `cascade: boolean` - If set to true, the related object will be inserted and update in the database.
* `onDelete: "RESTRICT"|"CASCADE"|"SET NULL"` - specifies how foreign key should behave when referenced object is deleted
* `primary: boolean` - Indicates whether this relation's column will be a primary column or not.
* `nullable: boolean` - Indicates whether this relation's column is nullable or not. By default it is nullable.
It's not recommended to set it to false if you are using cascades in your relations.
## Cascades
@ -70,7 +66,7 @@ export class Question {
text: string;
@ManyToMany(type => Category, category => category.questions, {
cascadeInsert: true
cascade: true
})
@JoinTable()
categories: Category[];
@ -91,14 +87,7 @@ await connection.manager.save(question);
```
As you can see in this example we did not called `save` for `category1` and `category2`.
They will be automatically inserted, because we set `cascadeInsert` to true.
When using `cascadeUpdate` `save` is called for each object in, that is in a relation with the entity being saved.
This means, that each entity in the relation will be automatically changed if they exist in the database.
When using `cascadeRemove` `remove` is called for each object missing in the relation.
Good example of this method is the relation between `Question` and `Answer` entities.
When you remove a `Question` which has `answers: Answer[]` relation you want to remove all answers from the database as well.
They will be automatically inserted, because we set `cascade` to true.
Keep in mind - great power comes with great responsibility.
Cascades may seem a good and easy way to work with relations,

View File

@ -7,7 +7,7 @@ See what amazing new features we are expecting to land in the next TypeORM versi
We are planning to release a final stable `1.0.0` version somewhere 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:
`cascades`, `class and single table inheritance`, `naming strategy`, `subscribers`, `tree tables`.
`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.
TypeORM follows a semantic versioning and until `1.0.0` breaking changes may appear in `0.x.x` versions,
@ -46,7 +46,7 @@ npm i typeorm@next
- [ ] create example how to use TypeORM in Electron apps
- [ ] finish naming strategy implementation
- [ ] finish subscribers and listeners implementation
- [ ] refactor persistence mechanizm
- [ ] fix all issues with cascades and make stable functionality
- [x] refactor persistence mechanism
- [x] fix all issues with cascades and make stable functionality
- [ ] implement API for manual migration creation
- [ ] add sql.js driver
- [x] add sql.js driver

View File

@ -96,7 +96,7 @@ module.exports = {
target: "Category",
type: "many-to-many",
joinTable: true,
cascadeInsert: true
cascade: true
}
}
};

View File

@ -16,14 +16,12 @@ export class Image {
post: Post;
@ManyToOne(type => Post, post => post.secondaryImages, {
cascadeInsert: true
cascade: ["insert"]
})
secondaryPost: Post;
@OneToOne(type => ImageDetails, details => details.image, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn()
details: ImageDetails;

View File

@ -23,16 +23,13 @@ export class Post {
text: string;
@OneToOne(type => PostDetails, details => details.post, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn()
details: PostDetails;
@OneToMany(type => Image, image => image.post, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
images: Image[] = [];
@ -40,8 +37,7 @@ export class Post {
secondaryImages: Image[];
@ManyToOne(type => Cover, cover => cover.posts, {
cascadeInsert: true,
cascadeRemove: true
cascade: ["insert"]
})
@JoinColumn({ name: "coverId" })
cover: Cover;
@ -52,8 +48,7 @@ export class Post {
coverId: number;
@ManyToMany(type => Category, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: Category[];

View File

@ -19,13 +19,12 @@ export class PostDetails {
post: Post;
@OneToMany(type => Category, category => category.details, {
cascadeInsert: true
cascade: ["insert"]
})
categories: Category[];
@ManyToOne(type => Chapter, chapter => chapter.postDetails, {
cascadeInsert: true,
cascadeRemove: true
cascade: ["insert"]
})
chapter: Chapter;

View File

@ -15,9 +15,7 @@ export class BaseObject extends BasePost {
title: string;
@ManyToOne(type => PostAuthor, post => post.posts, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
author: PostAuthor;

View File

@ -11,8 +11,7 @@ export class Blog extends BaseObject {
text: string;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -11,8 +11,7 @@ export class Post extends BaseObject {
text: string;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -12,8 +12,7 @@ export class PostCategory {
name: string;
@ManyToMany(type => Post, post => post.categories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[] = [];

View File

@ -18,17 +18,14 @@ export class Post {
text: string;
@OneToOne(type => PostAuthor, author => author.post, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn() // comment this and you'll get an error because JoinColumn must be at least on one side of the one-to-one relationship
// @JoinTable() // uncomment this and you'll get an error because JoinTable is not allowed here (only many-to-many)
author: PostAuthor;
@OneToMany(type => PostAuthor, author => author.editedPost, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
// @JoinColumn() // uncomment this and you'll get an error, because JoinColumn is not allowed here (only many-to-one/one-to-one)
// @JoinTable() // uncomment this and you'll get an error because JoinTable is not allowed here (only many-to-many)

View File

@ -12,8 +12,7 @@ export class Author {
name: string;
@OneToMany(type => Post, post => post.author, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Promise<Post[]>;

View File

@ -18,15 +18,13 @@ export class Post {
text: string;
@ManyToOne(type => Author, author => author.posts, {
cascadeInsert: true,
cascadeRemove: true,
cascade: ["insert"],
onDelete: "SET NULL"
})
author: Promise<Author|null>;
@ManyToMany(type => Category, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: Promise<Category[]>;

View File

@ -20,17 +20,14 @@ export class Post {
@Column()
text: string;
@ManyToOne(type => Author, { cascadeAll: true })
@ManyToOne(type => Author, { cascade: true })
author: Author;
@ManyToMany(type => Category, {
cascadeInsert: true,
cascadeUpdate: true
})
@ManyToMany(type => Category, { cascade: true })
@JoinTable()
categories: Category[];
@OneToOne(type => PostMetadata, { cascadeAll: true })
@OneToOne(type => PostMetadata, { cascade: true })
@JoinColumn()
metadata: PostMetadata;

View File

@ -21,9 +21,7 @@ export class Post {
// post has relation with category, however inverse relation is not set (category does not have relation with post set)
@OneToOne(type => PostCategory, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn()
category: PostCategory;
@ -31,7 +29,7 @@ export class Post {
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// relation it will be inserted automatically to the db when you save this Post entity
@OneToOne(type => PostDetails, details => details.post, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinColumn()
details: PostDetails;
@ -39,24 +37,20 @@ export class Post {
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@OneToOne(type => PostImage, image => image.post, {
cascadeUpdate: true
cascade: ["update"]
})
@JoinColumn()
image: PostImage;
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@OneToOne(type => PostMetadata, metadata => metadata.post, {
cascadeRemove: true
})
@OneToOne(type => PostMetadata, metadata => metadata.post)
@JoinColumn()
metadata: PostMetadata|null;
// post has relation with details. full cascades here
@OneToOne(type => PostInformation, information => information.post, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn()
information: PostInformation;

View File

@ -17,9 +17,7 @@ export class PostDetails {
metadata: string;
@OneToOne(type => Post, post => post.details, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
post: Post;

View File

@ -11,7 +11,7 @@ export class PostInformation {
text: string;
@OneToOne(type => Post, post => post.information, {
cascadeUpdate: true,
cascade: ["update"]
})
post: Post;

View File

@ -12,8 +12,7 @@ export class Author {
name: string;
@OneToMany(type => Post, post => post.author, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[];

View File

@ -19,7 +19,7 @@ export class Post {
text: string;
@ManyToOne(type => Author, author => author.posts, {
cascadeAll: true
cascade: true
})
@JoinColumn({ // todo: not yet fixed
name: "user"
@ -27,8 +27,7 @@ export class Post {
author: Author;
@ManyToMany(type => Category, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable({
name: "_post_categories"

View File

@ -16,7 +16,7 @@ export class Category {
@TreeParent()
parentCategory: Category;
@TreeChildren({ cascadeInsert: true, cascadeUpdate: true })
@TreeChildren({ cascade: true })
childCategories: Category[];
@TreeLevelColumn()

View File

@ -18,13 +18,12 @@ export class Post {
text: string;
@ManyToMany(type => Category, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: Category[];
@ManyToOne(type => Author, { cascadeInsert: true })
@ManyToOne(type => Author, { cascade: ["insert"] })
author: Author|null;
}

View File

@ -18,9 +18,7 @@
"posts": {
"target": "Post",
"type": "many-to-many",
"cascadeInsert": true,
"cascadeUpdate": true,
"cascadeRemove": true,
"cascade": true,
"inverseSide": "categories"
}
}

View File

@ -22,17 +22,13 @@
"post": {
"target": "Post",
"type": "many-to-one",
"cascadeInsert": true,
"cascadeUpdate": true,
"cascadeRemove": true,
"cascade": true,
"inverseSide": "images"
},
"secondaryImages": {
"target": "Post",
"type": "many-to-one",
"cascadeInsert": true,
"cascadeUpdate": true,
"cascadeRemove": true,
"cascade": true,
"inverseSide": "secondaryImages"
}
}

View File

@ -24,17 +24,13 @@
"type": "one-to-one",
"joinColumn": true,
"inverseSide": "post",
"cascadeInsert": true,
"cascadeUpdate": true,
"cascadeRemove": true
"cascade": true
},
"images": {
"target": "Image",
"type": "one-to-many",
"inverseSide": "post",
"cascadeInsert": true,
"cascadeUpdate": true,
"cascadeRemove": true
"cascade": true
},
"secondaryImages": {
"target": "Image",
@ -45,9 +41,7 @@
"target": "Category",
"type": "many-to-many",
"joinTable": true,
"cascadeInsert": true,
"cascadeUpdate": true,
"cascadeRemove": true,
"cascade": true,
"inverseSide": "posts"
}
}

View File

@ -20,38 +20,32 @@ export class Post {
// post has relation with category, however inverse relation is not set (category does not have relation with post set)
@ManyToOne(type => PostCategory, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
category: PostCategory;
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// relation it will be inserted automatically to the db when you save this Post entity
@ManyToOne(type => PostDetails, details => details.posts, {
cascadeInsert: true
cascade: ["insert"]
})
details: PostDetails;
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@ManyToOne(type => PostImage, image => image.posts, {
cascadeUpdate: true
cascade: ["update"]
})
image: PostImage;
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@ManyToOne(type => PostMetadata, metadata => metadata.posts, {
cascadeRemove: true
})
@ManyToOne(type => PostMetadata, metadata => metadata.posts)
metadata: PostMetadata|null;
// post has relation with details. full cascades here
@ManyToOne(type => PostInformation, information => information.posts, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
information: PostInformation;

View File

@ -26,8 +26,7 @@ export class PostDetails {
metadata: string|null;
@OneToMany(type => Post, post => post.details, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[];

View File

@ -11,7 +11,7 @@ export class PostInformation {
text: string;
@OneToMany(type => Post, post => post.information, {
cascadeUpdate: true,
cascade: ["update"],
})
posts: Post[];

View File

@ -17,12 +17,12 @@ export class Post {
text: string;
@ManyToOne(type => Author, {
cascadeInsert: true
cascade: ["insert"]
})
author: Author;
@ManyToMany(type => Category, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinTable()
categories: Category[];

View File

@ -11,7 +11,7 @@ export class Post {
title: string;
@ManyToOne(type => Author, {
cascadeInsert: true
cascade: ["insert"]
})
author: Author;

View File

@ -11,7 +11,7 @@ export class Post {
title: string;
@ManyToOne(type => Author, {
cascadeInsert: true
cascade: ["insert"]
})
author: Author;

View File

@ -21,8 +21,7 @@ export class Post {
// post has relation with category, however inverse relation is not set (category does not have relation with post set)
@ManyToMany(type => PostCategory, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[];
@ -30,7 +29,7 @@ export class Post {
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// relation it will be inserted automatically to the db when you save this Post entity
@ManyToMany(type => PostDetails, details => details.posts, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinTable()
details: PostDetails[];
@ -38,7 +37,7 @@ export class Post {
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@ManyToMany(type => PostImage, image => image.posts, {
cascadeUpdate: true
cascade: ["update"]
})
@JoinTable()
images: PostImage[];
@ -51,8 +50,7 @@ export class Post {
// post has relation with details. full cascades here
@ManyToMany(type => PostInformation, information => information.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
informations: PostInformation[];

View File

@ -26,8 +26,7 @@ export class PostDetails {
metadata: string|null;
@ManyToMany(type => Post, post => post.details, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[];

View File

@ -11,7 +11,7 @@ export class PostInformation {
text: string;
@ManyToMany(type => Post, post => post.informations, {
cascadeUpdate: true,
cascade: ["update"],
})
posts: Post[];

View File

@ -17,15 +17,12 @@ export class Post {
text: string;
@ManyToOne(type => PostAuthor, post => post.posts, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
author: PostAuthor;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -12,8 +12,7 @@ export class PostCategory {
name: string;
@ManyToMany(type => Post, post => post.categories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[] = [];

View File

@ -13,15 +13,12 @@ export class Blog extends BasePost {
text: string;
@ManyToOne(type => PostAuthor, post => post.posts, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
author: PostAuthor;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -13,15 +13,12 @@ export class Post extends BasePost {
text: string;
@ManyToOne(type => PostAuthor, post => post.posts, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
author: PostAuthor;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -12,8 +12,7 @@ export class PostCategory {
name: string;
@ManyToMany(type => Post, post => post.categories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[] = [];

View File

@ -17,15 +17,12 @@ export class Post {
text: string;
@ManyToOne(type => PostAuthor, post => post.posts, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
author: PostAuthor;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -12,8 +12,7 @@ export class PostCategory {
name: string;
@ManyToMany(type => Post, post => post.categories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[] = [];

View File

@ -15,43 +15,34 @@ export class Category {
name: string;
@OneToOne(type => Category, category => category.oneInverseCategory, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn()
oneCategory: Category;
@OneToOne(type => Category, category => category.oneCategory, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
oneInverseCategory: Category;
@ManyToOne(type => Category, category => category.oneManyCategories, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
oneManyCategory: Category;
@OneToMany(type => Category, category => category.oneManyCategory, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
oneManyCategories: Category[] = [];
@ManyToMany(type => Category, category => category.manyInverseCategories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
manyCategories: Category[] = [];
@ManyToMany(type => Category, category => category.manyCategories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
manyInverseCategories: Category[] = [];

View File

@ -24,14 +24,12 @@ export class Post {
text: string;
@ManyToOne(type => PostAuthor, post => post.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
author: PostAuthor;
@ManyToMany(type => PostCategory, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinTable()
categories: PostCategory[] = [];

View File

@ -18,8 +18,7 @@ export class PostCategory {
name: string;
@ManyToMany(type => Post, post => post.categories, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
posts: Post[] = [];

View File

@ -8,25 +8,13 @@ import {OnDeleteType} from "../../metadata/types/OnDeleteType";
export interface RelationOptions {
/**
* If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.
* This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.
* Sets cascades options for the given relation.
* If set to true then it means that related object can be allowed to be inserted or updated in the database.
* You can separately restrict cascades to insertion or updation using following syntax:
*
* cascade: ["insert", "update"] // include or exclude one of them
*/
cascadeAll?: boolean; // todo: replace with cascade: boolean|("insert"|"update")[]
/**
* If set to true then it means that related object can be allowed to be inserted to the db.
*/
cascadeInsert?: boolean;
/**
* If set to true then it means that related object can be allowed to be updated in the db.
*/
cascadeUpdate?: boolean;
/**
* If set to true then it means that related object can be allowed to be remove from the db.
*/
cascadeRemove?: boolean;
cascade?: boolean|("insert"|"update")[];
/**
* Indicates if relation column value can be nullable or not.

View File

@ -8,7 +8,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs";
* multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage
* entity1 and entity2 ids. This is owner side of the relationship.
*/
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean, eager?: boolean }): Function;
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, options?: RelationOptions): Function;
/**
* Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have
@ -17,7 +17,7 @@ export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, optio
*/
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
inverseSide?: string|((object: T) => any),
options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean, eager?: boolean }): Function;
options?: RelationOptions): Function;
/**
* Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have
@ -25,8 +25,8 @@ export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
* entity1 and entity2 ids. This is owner side of the relationship.
*/
export function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>,
inverseSideOrOptions?: string|((object: T) => any)|{ cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean, eager?: boolean },
options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean, eager?: boolean }): Function {
inverseSideOrOptions?: string|((object: T) => any)|RelationOptions,
options?: RelationOptions): Function {
let inverseSideProperty: string|((object: T) => any);
if (typeof inverseSideOrOptions === "object") {
options = <RelationOptions> inverseSideOrOptions;

View File

@ -9,7 +9,7 @@ import {RelationOptions} from "../options/RelationOptions";
* One-to-many relation allows to create type of relation when Entity2 can have multiple instances of Entity1.
* Entity1 have only one Entity2. Entity1 is an owner of the relationship, and storages Entity2 id on its own side.
*/
export function OneToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide: string|((object: T) => any), options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean, eager?: boolean, persistence?: boolean }): Function {
export function OneToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide: string|((object: T) => any), options?: RelationOptions): Function {
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;

View File

@ -5,7 +5,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs";
/**
* Marks a specific property of the class as a children of the tree.
*/
export function TreeChildren(options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function {
export function TreeChildren(options?: RelationOptions): Function {
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;

View File

@ -5,7 +5,7 @@ import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs";
/**
* Marks a specific property of the class as a parent of the tree.
*/
export function TreeParent(options?: { cascadeInsert?: boolean, cascadeUpdate?: boolean, lazy?: boolean }): Function {
export function TreeParent(options?: RelationOptions): Function {
return function (object: Object, propertyName: string) {
if (!options) options = {} as RelationOptions;

View File

@ -60,22 +60,7 @@ export interface EntitySchemaRelation {
* If set to true then it means that related object can be allowed to be inserted / updated / removed to the db.
* This is option a shortcut if you would like to set cascadeInsert, cascadeUpdate and cascadeRemove to true.
*/
cascadeAll?: boolean;
/**
* If set to true then it means that related object can be allowed to be inserted to the db.
*/
cascadeInsert?: boolean;
/**
* If set to true then it means that related object can be allowed to be updated in the db.
*/
cascadeUpdate?: boolean;
/**
* If set to true then it means that related object can be allowed to be remove from the db.
*/
cascadeRemove?: boolean;
cascade?: boolean|("insert"|"update")[];
/**
* Default database value.

View File

@ -97,10 +97,7 @@ export class EntitySchemaTransformer {
isTreeParent: relationSchema.isTreeParent,
isTreeChildren: relationSchema.isTreeChildren,
options: {
cascadeAll: relationSchema.cascadeAll,
cascadeInsert: relationSchema.cascadeInsert,
cascadeUpdate: relationSchema.cascadeUpdate,
cascadeRemove: relationSchema.cascadeRemove,
cascade: relationSchema.cascade,
nullable: relationSchema.nullable,
onDelete: relationSchema.onDelete
}

View File

@ -259,9 +259,8 @@ export class RelationMetadata {
this.givenInverseSidePropertyFactory = args.inverseSideProperty;
this.isLazy = args.isLazy || false;
this.isCascadeInsert = args.options.cascadeInsert || args.options.cascadeAll || false;
this.isCascadeUpdate = args.options.cascadeUpdate || args.options.cascadeAll || false;
this.isCascadeRemove = args.options.cascadeRemove || args.options.cascadeAll || false;
this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("insert") !== -1);
this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("update") !== -1);
this.isNullable = args.options.nullable !== false;
this.onDelete = args.options.onDelete;
this.isPrimary = args.options.primary || false;

View File

@ -12,7 +12,7 @@ export class Post {
key: number;
@OneToOne(type => PostDetails, details => details.post, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinColumn()
details: PostDetails;

View File

@ -10,7 +10,7 @@ export class PostDetails {
keyword: string;
@OneToOne(type => Post, post => post.details, {
cascadeInsert: true
cascade: ["insert"]
})
post: Post;

View File

@ -17,7 +17,7 @@ export class Category {
@TreeParent()
parentCategory: Category;
@TreeChildren({ cascadeInsert: true, cascadeUpdate: true })
@TreeChildren({ cascade: true })
childCategories: Category[];
@TreeLevelColumn()

View File

@ -14,7 +14,7 @@ export class Post {
@Column()
title: string;
@ManyToMany(type => Category, category => category.posts, { cascadeInsert: true })
@ManyToMany(type => Category, category => category.posts, { cascade: ["insert"] })
@JoinTable()
categories: Category[];

View File

@ -19,7 +19,7 @@ export class Profile {
@OneToOne(type => Photo, {
nullable: false,
cascadeInsert: true
cascade: ["insert"]
})
@JoinColumn()
photo: Photo;

View File

@ -9,7 +9,7 @@ export class User {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(type => Profile, profile => profile.user, { cascadeInsert: true })
@OneToOne(type => Profile, profile => profile.user, { cascade: ["insert"] })
profile: Profile;
}

View File

@ -12,19 +12,19 @@ export class Answer {
id: number;
@ManyToOne(type => Question, question => question.answers, {
cascadeInsert: true,
cascade: ["insert"],
nullable: false
})
question: Question;
@ManyToOne(type => Photo, {
cascadeInsert: true,
cascade: ["insert"],
nullable: false
})
photo: Photo;
@ManyToOne(type => User, {
cascadeInsert: true,
cascade: ["insert"],
nullable: false
})
user: User;

View File

@ -9,7 +9,7 @@ export class Question {
@PrimaryGeneratedColumn()
id: number;
@OneToMany(type => Answer, answer => answer.question, { cascadeInsert: true })
@OneToMany(type => Answer, answer => answer.question, { cascade: ["insert"] })
answers: Answer[];
}

View File

@ -10,7 +10,7 @@ export class User {
id: number;
@ManyToOne(type => Question, {
cascadeInsert: true,
cascade: ["insert"],
nullable: true
})
question: Question;

View File

@ -16,7 +16,7 @@ export class Category {
name: string;
@OneToMany(type => Post, post => post.category, {
cascadeInsert: true
cascade: ["insert"]
})
posts: Post[];

View File

@ -16,7 +16,7 @@ export class Post {
title: string;
@ManyToOne(type => Category, category => category.posts, {
cascadeInsert: true
cascade: ["insert"]
})
category: Category;

View File

@ -20,7 +20,7 @@ export class Category {
metadataId: number;
@OneToOne(type => CategoryMetadata, metadata => metadata.category, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinColumn({ name: "metadataId" })
metadata: CategoryMetadata;

View File

@ -18,8 +18,7 @@ export class Post {
categoryId: number;
@ManyToOne(type => Category, category => category.posts, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinColumn({ name: "categoryId" })
category: Category;

View File

@ -13,7 +13,7 @@ export class User {
@Column()
name: string;
@ManyToOne(type => Post, { cascadeUpdate: true })
@ManyToOne(type => Post, { cascade: ["update"] })
post: Post;
}

View File

@ -14,8 +14,7 @@ export class Category {
name: string;
@ManyToOne(type => Post, post => post.categories, {
cascadeInsert: true,
cascadeUpdate: true,
cascade: true,
onDelete: "SET NULL"
})
post?: Post|null|number;

View File

@ -14,8 +14,7 @@ export class Category {
name: string;
@ManyToOne(type => Post, {
cascadeInsert: true,
cascadeUpdate: true,
cascade: true,
onDelete: "SET NULL"
})
post?: Post|null|number;

View File

@ -22,7 +22,7 @@ export class Post {
counters: Counters;
@ManyToMany(type => Category, category => category.posts, {
cascadeUpdate: true
cascade: ["update"],
})
@JoinTable()
categories: Category[];

View File

@ -13,7 +13,7 @@ export class Post {
@Column()
title: string;
@OneToMany(type => Category, category => category.post, { cascadeInsert: true })
@OneToMany(type => Category, category => category.post, { cascade: ["insert"] })
categories: Category[];
}

View File

@ -14,7 +14,7 @@ export class Category {
name: string;
@OneToMany(type => Post, post => post.category, {
cascadeInsert: true
cascade: ["insert"]
})
posts: Post[];

View File

@ -8,7 +8,7 @@ export class Post {
@ManyToOne(type => Category, category => category.posts, {
primary: true,
cascadeInsert: true
cascade: ["insert"]
})
category: Category;

View File

@ -14,10 +14,10 @@ export class Category {
@Column()
name: string;
@TreeParent({ cascadeInsert: true, cascadeUpdate: true })
@TreeParent({ cascade: true })
parentCategory: Category;
@TreeChildren({ cascadeInsert: true, cascadeUpdate: true })
@TreeChildren({ cascade: true })
childCategories: Category[];
@TreeLevelColumn()

View File

@ -15,11 +15,11 @@ export class Post {
@Column()
title: string;
@OneToOne(type => Category, { cascadeAll: true })
@OneToOne(type => Category, { cascade: true })
@JoinColumn()
category: Category|null;
@OneToOne(type => PostMetadata, metadata => metadata.post, { cascadeAll: true })
@OneToOne(type => PostMetadata, metadata => metadata.post, { cascade: true })
@JoinColumn()
metadata: PostMetadata|null;

View File

@ -15,7 +15,7 @@ export class Department {
name: string;
@OneToOne(type => Employee, {
cascadeInsert: true,
cascade: ["insert"],
nullable: false
})
@JoinColumn()

View File

@ -20,8 +20,7 @@ export class Request {
success: boolean;
@OneToOne(type => Ticket, ticket => ticket.request, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
ticket: Ticket;

View File

@ -15,9 +15,7 @@ export class Ticket {
name: string;
@OneToOne(type => Request, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
cascade: true
})
@JoinColumn()
request: Request;

View File

@ -30,8 +30,7 @@ export class Game {
isReviewed: boolean;
@ManyToMany(type => Platform, platform => platform.games, {
cascadeInsert: true, // allow to insert a new platform on game save
cascadeUpdate: true, // allow to update a platform on game save
cascade: true
})
@JoinTable()
platforms: Platform[];

View File

@ -23,8 +23,7 @@ export class Platform {
slug: string;
@ManyToMany(type => Game, game => game.platforms, {
cascadeInsert: true, // allow to insert a new game on platform save
cascadeUpdate: true, // allow to update an game on platform save
cascade: true
})
games: Game[];

View File

@ -17,12 +17,12 @@ export class Post {
title: string;
@ManyToOne(() => Category, category => category.posts, {
cascadeInsert: true
cascade: ["insert"]
})
category: Promise<Category>;
@ManyToMany(type => Tag, tag => tag.posts, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinTable()
tags: Promise<Tag[]>;

View File

@ -13,8 +13,7 @@ export class ActivityEntity {
endDate: Date;
@ManyToMany(type => TileEntity, tile => tile.activities, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
tiles: TileEntity[];

View File

@ -10,21 +10,18 @@ export class TileEntity {
id: number;
@ManyToMany(type => TileEntity, tile => tile.children, {
cascadeInsert: true,
cascadeUpdate: false
cascade: ["insert"]
})
@JoinTable()
parents: TileEntity[];
@ManyToMany(type => TileEntity, tile => tile.parents, {
cascadeInsert: true,
cascadeUpdate: false
cascade: ["insert"]
})
children: TileEntity[];
@ManyToMany(type => ActivityEntity, activity => activity.tiles, {
cascadeInsert: true,
cascadeUpdate: false
cascade: ["insert"]
})
@JoinTable()
activities: ActivityEntity[];

View File

@ -14,7 +14,7 @@ export class Post {
title: string;
@ManyToMany(() => Category, category => category.posts, {
cascadeInsert: true
cascade: ["insert"]
})
categories: Category[];

View File

@ -14,7 +14,7 @@ export class Post {
title: string;
@ManyToOne(() => Category, category => category.posts, {
cascadeInsert: true
cascade: ["insert"]
})
category: Promise<Category>;

View File

@ -12,8 +12,7 @@ export class AccessToken {
primaryKey: number;
@OneToOne(type => User, user => user.access_token, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
user: User;

View File

@ -17,8 +17,7 @@ export class User {
email: string;
@OneToOne(type => AccessToken, token => token.user, {
cascadeInsert: true,
cascadeUpdate: true
cascade: true
})
@JoinColumn()
access_token: AccessToken;

View File

@ -9,13 +9,13 @@ export class PostCategory {
@ManyToOne(type => Post, post => post.categories, {
primary: true,
cascadeInsert: true
cascade: ["insert"]
})
post: Post;
@ManyToOne(type => Category, category => category.posts, {
primary: true,
cascadeInsert: true
cascade: ["insert"]
})
category: Category;

View File

@ -14,7 +14,7 @@ export class Post {
title: string;
@OneToMany(() => Category, category => category.post, {
cascadeInsert: true
cascade: ["insert"]
})
categories: Category[];

View File

@ -25,7 +25,7 @@ export class Artikel {
@Column({ name: "artikel_saison" })
saison: string;
@ManyToOne(type => Kollektion, { cascadeAll: true })
@ManyToOne(type => Kollektion, { cascade: true })
@JoinColumn({ name: "id_kollektion" })
kollektion: Kollektion;

View File

@ -10,7 +10,7 @@ export class UserCredential {
@OneToOne(() => User, {
primary: true,
cascadeAll: true,
cascade: true,
})
@JoinColumn({
name: "id",

View File

@ -13,10 +13,10 @@ export class Category {
@Column()
name: string;
@TreeParent({ cascadeInsert: true, cascadeUpdate: true })
@TreeParent({ cascade: true })
parentCategory: Category;
@TreeChildren({ cascadeInsert: true, cascadeUpdate: true })
@TreeChildren({ cascade: true })
childCategories: Category[];
}

View File

@ -15,7 +15,7 @@ export class Post {
title: string;
@ManyToMany(type => Category, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinTable()
categories: Category[];

View File

@ -14,7 +14,7 @@ export class User {
@Column() handedness: string;
@ManyToMany(type => Role, {
cascadeInsert: true
cascade: ["insert"]
})
@JoinTable()
roles: Role[];