Skip to content

Commit 78d169a

Browse files
committed
docs: de-addon-docs-ify Ember Data Model guide
1 parent 51ec9ac commit 78d169a

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

docs/ember-data/models.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,20 @@ The type returned by the `@hasMany` decorator depends on whether the relationshi
7070

7171
So, for example, you might define a class like this:
7272

73-
<DocsSnippet @name='belongs-to.ts' @title='my-app/models/belongs-to.ts' @showCopy={{false}} />
73+
```ts
74+
import Model, { belongsTo } from '@ember-data/model';
75+
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
76+
import User from './user';
77+
import Site from './site';
78+
79+
export default class Post extends Model {
80+
@belongsTo('user')
81+
declare user: DS.PromiseObject<User>;
82+
83+
@belongsTo('site', { async: false })
84+
declare site: Site;
85+
}
86+
```
7487

7588
These are *type*-safe to define as always present, that is to leave off the `?` optional marker:
7689

@@ -89,7 +102,21 @@ The type returned by the `@hasMany` decorator depends on whether the relationshi
89102

90103
So, for example, you might define a class like this:
91104

92-
<DocsSnippet @name='has-many.ts' @title='my-app/models/has-many.ts' @showCopy={{false}} />
105+
```ts
106+
import Model, { hasMany } from '@ember-data/model';
107+
import EmberArray from '@ember/array';
108+
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
109+
import Comment from './comment';
110+
import User from './user';
111+
112+
export default class Thread extends Model {
113+
@hasMany('comment')
114+
declare comment: DS.PromiseManyArray<Comment>;
115+
116+
@hasMany('user', { async: false })
117+
declare participants: EmberArray<User>;
118+
}
119+
```
93120

94121
The same basic rules about the safety of these lookups as with `@belongsTo` apply to these types. The difference is just that in `@hasMany` the resulting types are *arrays* rather than single objects.
95122

tests/dummy/app/snippets/belongs-to.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/dummy/app/snippets/has-many.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)