Skip to content

Commit

Permalink
docs: typo on decorator-reference.md and many-to-many-relations.md (
Browse files Browse the repository at this point in the history
#8448)

* docs: fix a typo on `decorator-reference.md`

fix double spacing and improve formatting consistency on `many-to-many-relations.md`

* docs: add code syntax highlight on `leftJoinAndSelect`
  • Loading branch information
audwinoyong committed Dec 10, 2021
1 parent 54cf660 commit 2bf93d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docs/decorator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ If `true`, MySQL automatically adds the `UNSIGNED` attribute to this column.
* `collation: string` - Defines a column collation.
* `enum: string[]|AnyEnum` - Used in `enum` column type to specify list of allowed enum values.
You can specify array of values or specify a enum class.
* `enumName: string` - A name for generated enum type. If not specified, TypeORM will generate a enum type from entity and column names - so it's neccessary if you intend to use the same enum type in different tables.
* `enumName: string` - A name for generated enum type. If not specified, TypeORM will generate a enum type from entity and column names - so it's necessary if you intend to use the same enum type in different tables.
* `asExpression: string` - Generated column expression. Used only in [MySQL](https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html) and [Postgres](https://www.postgresql.org/docs/12/ddl-generated-columns.html).
* `generatedType: "VIRTUAL"|"STORED"` - Generated column type. Used only in [MySQL](https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html) and [Postgres (Only "STORED")](https://www.postgresql.org/docs/12/ddl-generated-columns.html).
* `hstoreType: "object"|"string"` - Return type of `HSTORE` column. Returns value as string or as object. Used only in [Postgres](https://www.postgresql.org/docs/9.6/static/hstore.html).
Expand Down Expand Up @@ -499,7 +499,7 @@ export class Post {
Used for `many-to-many` relations and describes join columns of the "junction" table.
Junction table is a special, separate table created automatically by TypeORM with columns referenced to the related entities.
You can change the name of the generated "junction" table and also the column names inside the junction table and their referenced columns with the `joinColumn`- and `inverseJoinColumn` attributes.
You can change the name of the generated "junction" table and also the column names inside the junction table and their referenced columns with the `joinColumn`- and `inverseJoinColumn` attributes.
Example:
```typescript
Expand Down
34 changes: 13 additions & 21 deletions docs/many-to-many-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* [Saving many-to-many relations](#saving-many-to-many-relations)
* [Deleting many-to-many relations](#deleting-many-to-many-relations)
* [Loading many-to-many relations](#loading-many-to-many-relations)
* [bi-directional relations](#bi-directional-relations)
* [Bi-directional relations](#bi-directional-relations)
* [many-to-many relations with custom properties](#many-to-many-relations-with-custom-properties)

## What are many-to-many relations
Expand All @@ -14,27 +14,24 @@ Let's take for example `Question` and `Category` entities.
A question can have multiple categories, and each category can have multiple questions.

```typescript
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";

@Entity()
export class Category {

@PrimaryGeneratedColumn()
id: number;

@Column()
name: string;

}
```

```typescript
import {Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable} from "typeorm";
import {Category} from "./Category";
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from "typeorm";
import { Category } from "./Category";

@Entity()
export class Question {

@PrimaryGeneratedColumn()
id: number;

Expand All @@ -47,7 +44,6 @@ export class Question {
@ManyToMany(() => Category)
@JoinTable()
categories: Category[];

}
```

Expand Down Expand Up @@ -129,20 +125,19 @@ category2.name = "zoo";

const question = new Question();
question.categories = [category1, category2];
const newQuestion = await connection.manager.save(question);
const newQuestion = await connection.manager.save(question);

await connection.manager.softRemove(newQuestion);
```

In this example we did not call save or softRemove for category1 and category2, but they will be automatically saved and soft-deleted when the cascade of relation options is set to true like this:

```typescript
import {Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable} from "typeorm";
import {Category} from "./Category";
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from "typeorm";
import { Category } from "./Category";

@Entity()
export class Question {

@PrimaryGeneratedColumn()
id: number;

Expand All @@ -151,7 +146,6 @@ export class Question {
})
@JoinTable()
categories: Category[];

}
```

Expand All @@ -174,9 +168,9 @@ const questions = await connection
.getMany();
```

With eager loading enabled on a relation, you don't have to specify relations in the find command as it will ALWAYS be loaded automatically. If you use QueryBuilder eager relations are disabled, you have to use leftJoinAndSelect to load the relation.
With eager loading enabled on a relation, you don't have to specify relations in the find command as it will ALWAYS be loaded automatically. If you use QueryBuilder eager relations are disabled, you have to use `leftJoinAndSelect` to load the relation.

## bi-directional relations
## Bi-directional relations

Relations can be uni-directional and bi-directional.
Uni-directional relations are relations with a relation decorator only on one side.
Expand All @@ -185,12 +179,11 @@ Bi-directional relations are relations with decorators on both sides of a relati
We just created a uni-directional relation. Let's make it bi-directional:

```typescript
import {Entity, PrimaryGeneratedColumn, Column, ManyToMany} from "typeorm";
import {Question} from "./Question";
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany } from "typeorm";
import { Question } from "./Question";

@Entity()
export class Category {

@PrimaryGeneratedColumn()
id: number;

Expand All @@ -199,13 +192,12 @@ export class Category {

@ManyToMany(() => Question, question => question.categories)
questions: Question[];

}
```

```typescript
import {Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable} from "typeorm";
import {Category} from "./Category";
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from "typeorm";
import { Category } from "./Category";

@Entity()
export class Question {
Expand Down

0 comments on commit 2bf93d4

Please sign in to comment.