mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
docs: add in an example for 4526 (#9538)
* docs: add in an example for 4526 * small fixes Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
This commit is contained in:
parent
658604d0ae
commit
d71e9c4394
@ -57,8 +57,8 @@ Install all TypeORM dependencies by running this command:
|
||||
npm install
|
||||
```
|
||||
|
||||
During installation you may have some problems with some dependencies.
|
||||
For example to proper install oracle driver you need to follow all instructions from
|
||||
During installation, you may have some problems with some dependencies.
|
||||
For example to properly install oracle driver you need to follow all instructions from
|
||||
[node-oracle documentation](https://github.com/oracle/node-oracledb).
|
||||
|
||||
## ORM config
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
- [How to load relations in entities](#how-to-load-relations-in-entities)
|
||||
- [Avoid relation property initializers](#avoid-relation-property-initializers)
|
||||
- [Avoid foreign key constraint creation](#avoid-foreign-key-constraint-creation)
|
||||
- [Avoid circular import errors](#avoid-circular-import-errors)
|
||||
|
||||
## How to create self referencing relation
|
||||
|
||||
@ -262,3 +263,43 @@ export class ActionLog {
|
||||
person: Person
|
||||
}
|
||||
```
|
||||
|
||||
## Avoid circular import errors
|
||||
|
||||
Here is an example if you want to define your entities, and you don't want those to cause errors in some environments.
|
||||
In this situation we have Action.ts and Person.ts importing each other for a many-to-many relationship.
|
||||
We use import type so that we can use the type information without any JavaScript code being generated.
|
||||
|
||||
```typescript
|
||||
import { Entity, PrimaryColumn, Column, ManytoMany } from "typeorm"
|
||||
import type { Person } from "./Person"
|
||||
|
||||
@Entity()
|
||||
export class ActionLog {
|
||||
@PrimaryColumn()
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
date: Date
|
||||
|
||||
@Column()
|
||||
action: string
|
||||
|
||||
@ManyToMany("Person", "id")
|
||||
person: Person
|
||||
}
|
||||
```
|
||||
|
||||
```typescript
|
||||
import { Entity, PrimaryColumn, ManytoMany } from "typeorm"
|
||||
import type { ActionLog } from "./Action"
|
||||
|
||||
@Entity()
|
||||
export class Person {
|
||||
@PrimaryColumn()
|
||||
id: number
|
||||
|
||||
@ManyToMany("ActionLog", "id")
|
||||
log: ActionLog
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user