You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ember-data/models.md
+18-8Lines changed: 18 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,17 @@ export default class User extends Model {
58
58
}
59
59
```
60
60
61
-
## `@belongsTo`
61
+
## Relationships
62
+
63
+
Relationships between models in Ember Data rely on importing the related models, like `import User from './user';`. This, naturally, can cause a recursive loop, as `/app/models/post.ts` imports `User` from `/app/models/user.ts`, and `/app/models/user.ts` imports `Post` from `/app/models/post.ts`. Recursive importing triggers an [`import/no-cycle`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md) error from eslint.
64
+
65
+
To avoid these errors, use of [type-only imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html), available since TypeScript 3.8:
66
+
67
+
```ts
68
+
importtypeUserfrom'./user';
69
+
```
70
+
71
+
### `@belongsTo`
62
72
63
73
The type returned by the `@belongsTo` decorator depends on whether the relationship is `{ async: true }`\(which it is by default\).
64
74
@@ -68,9 +78,9 @@ The type returned by the `@belongsTo` decorator depends on whether the relations
68
78
So, for example, you might define a class like this:
@@ -88,7 +98,7 @@ These are _type_-safe to define as always present, that is to leave off the `?`
88
98
89
99
Note, however, that this type-safety is not a guarantee of there being no runtime error: you still need to uphold the contract for non-async relationships \(that is: loading the data first, or side-loading it with the request\) to avoid throwing an error!
90
100
91
-
## `@hasMany`
101
+
###`@hasMany`
92
102
93
103
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }`\(which it is by default\).
94
104
@@ -98,9 +108,9 @@ The type returned by the `@hasMany` decorator depends on whether the relationshi
98
108
So, for example, you might define a class like this:
0 commit comments