@ember-data/model 5.4.0-alpha.32 → 5.4.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/addon/-private.js +1 -1
  2. package/addon/{has-many-Qm5aUQol.js → has-many-Mz5PIxmL.js} +10 -0
  3. package/addon/{has-many-Qm5aUQol.js.map → has-many-Mz5PIxmL.js.map} +1 -1
  4. package/addon/index.js +1 -1
  5. package/addon/model-eXqU5A13.js.map +1 -1
  6. package/package.json +19 -19
  7. package/unstable-preview-types/-private/attr.d.ts +170 -168
  8. package/unstable-preview-types/-private/attr.type-test.d.ts +3 -1
  9. package/unstable-preview-types/-private/belongs-to.d.ts +179 -178
  10. package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -1
  11. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +3 -1
  12. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +7 -5
  13. package/unstable-preview-types/-private/errors.d.ts +288 -286
  14. package/unstable-preview-types/-private/has-many.d.ts +168 -167
  15. package/unstable-preview-types/-private/has-many.d.ts.map +1 -1
  16. package/unstable-preview-types/-private/has-many.type-test.d.ts +3 -1
  17. package/unstable-preview-types/-private/hooks.d.ts +12 -10
  18. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +60 -58
  19. package/unstable-preview-types/-private/many-array.d.ts +192 -189
  20. package/unstable-preview-types/-private/many-array.d.ts.map +1 -1
  21. package/unstable-preview-types/-private/model-for-mixin.d.ts +5 -3
  22. package/unstable-preview-types/-private/model-methods.d.ts +32 -30
  23. package/unstable-preview-types/-private/model.d.ts +103 -100
  24. package/unstable-preview-types/-private/model.type-test.d.ts +3 -1
  25. package/unstable-preview-types/-private/notify-changes.d.ts +7 -5
  26. package/unstable-preview-types/-private/promise-belongs-to.d.ts +45 -43
  27. package/unstable-preview-types/-private/promise-many-array.d.ts +127 -125
  28. package/unstable-preview-types/-private/promise-proxy-base.d.ts +35 -32
  29. package/unstable-preview-types/-private/record-state.d.ts +86 -84
  30. package/unstable-preview-types/-private/references/belongs-to.d.ts +471 -469
  31. package/unstable-preview-types/-private/references/has-many.d.ts +486 -484
  32. package/unstable-preview-types/-private/schema-provider.d.ts +25 -23
  33. package/unstable-preview-types/-private/util.d.ts +10 -8
  34. package/unstable-preview-types/-private.d.ts +11 -9
  35. package/unstable-preview-types/hooks.d.ts +4 -2
  36. package/unstable-preview-types/index.d.ts +74 -45
  37. package/unstable-preview-types/migration-support.d.ts +10 -8
@@ -1,501 +1,503 @@
1
- import type { ResourceEdge } from '@ember-data/graph/-private/edges/resource';
2
- import type { Graph } from '@ember-data/graph/-private/graph';
3
- import type Store from '@ember-data/store';
4
- import type { StableRecordIdentifier } from '@warp-drive/core-types';
5
- import type { TypeFromInstanceOrString } from '@warp-drive/core-types/record';
6
- import type { Links, Meta, SingleResourceDocument, SingleResourceRelationship } from '@warp-drive/core-types/spec/raw';
7
- import type { IsUnknown } from '../belongs-to';
8
- /**
9
- A `BelongsToReference` is a low-level API that allows access
10
- and manipulation of a belongsTo relationship.
11
-
12
- It is especially useful when you're dealing with `async` relationships
13
- from `@ember-data/model` as it allows synchronous access to
14
- the relationship data if loaded, as well as APIs for loading, reloading
15
- the data or accessing available information without triggering a load.
16
-
17
- It may also be useful when using `sync` relationships with `@ember-data/model`
18
- that need to be loaded/reloaded with more precise timing than marking the
19
- relationship as `async` and relying on autofetch would have allowed.
20
-
21
- However,keep in mind that marking a relationship as `async: false` will introduce
22
- bugs into your application if the data is not always guaranteed to be available
23
- by the time the relationship is accessed. Ergo, it is recommended when using this
24
- approach to utilize `links` for unloaded relationship state instead of identifiers.
25
-
26
- Reference APIs are entangled with the relationship's underlying state,
27
- thus any getters or cached properties that utilize these will properly
28
- invalidate if the relationship state changes.
29
-
30
- References are "stable", meaning that multiple calls to retrieve the reference
31
- for a given relationship will always return the same HasManyReference.
32
-
33
- @class BelongsToReference
34
- @public
35
- */
36
- export default class BelongsToReference<T = unknown, K extends string = IsUnknown<T> extends true ? string : keyof T & string, Related = K extends keyof T ? Awaited<T[K]> : unknown> {
37
- graph: Graph;
38
- store: Store;
39
- belongsToRelationship: ResourceEdge;
40
- /**
41
- * The field name on the parent record for this has-many relationship.
42
- *
43
- * @property {String} key
44
- * @public
45
- */
46
- key: K;
47
- /**
48
- * The type of resource this relationship will contain.
49
- *
50
- * @property {String} type
51
- * @public
52
- */
53
- type: TypeFromInstanceOrString<Related>;
54
- ___token: object;
55
- ___identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>;
56
- ___relatedToken: object | null;
57
- _ref: number;
58
- constructor(store: Store, graph: Graph, parentIdentifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>, belongsToRelationship: ResourceEdge, key: K);
59
- destroy(): void;
60
- /**
61
- * The identifier of the record that this reference refers to.
62
- * `null` if no related record is known.
63
- *
64
- * @property {StableRecordIdentifier | null} identifier
65
- * @public
66
- */
67
- get identifier(): StableRecordIdentifier<TypeFromInstanceOrString<Related>> | null;
68
- /**
69
- The `id` of the record that this reference refers to. Together, the
70
- `type()` and `id()` methods form a composite key for the identity
71
- map. This can be used to access the id of an async relationship
72
- without triggering a fetch that would normally happen if you
73
- attempted to use `record.relationship.id`.
74
-
75
- Example
76
-
77
- ```javascript
78
- // models/blog.js
79
- import Model, { belongsTo } from '@ember-data/model';
80
-
81
- export default class BlogModel extends Model {
82
- @belongsTo('user', { async: true, inverse: null }) user;
83
- }
84
-
85
- let blog = store.push({
86
- data: {
87
- type: 'blog',
88
- id: 1,
89
- relationships: {
90
- user: {
91
- data: { type: 'user', id: 1 }
1
+ declare module '@ember-data/model/-private/references/belongs-to' {
2
+ import type { ResourceEdge } from '@ember-data/graph/-private/edges/resource';
3
+ import type { Graph } from '@ember-data/graph/-private/graph';
4
+ import type Store from '@ember-data/store';
5
+ import type { StableRecordIdentifier } from '@warp-drive/core-types';
6
+ import type { TypeFromInstanceOrString } from '@warp-drive/core-types/record';
7
+ import type { Links, Meta, SingleResourceDocument, SingleResourceRelationship } from '@warp-drive/core-types/spec/raw';
8
+ import type { IsUnknown } from '@ember-data/model/-private/belongs-to';
9
+ /**
10
+ A `BelongsToReference` is a low-level API that allows access
11
+ and manipulation of a belongsTo relationship.
12
+
13
+ It is especially useful when you're dealing with `async` relationships
14
+ from `@ember-data/model` as it allows synchronous access to
15
+ the relationship data if loaded, as well as APIs for loading, reloading
16
+ the data or accessing available information without triggering a load.
17
+
18
+ It may also be useful when using `sync` relationships with `@ember-data/model`
19
+ that need to be loaded/reloaded with more precise timing than marking the
20
+ relationship as `async` and relying on autofetch would have allowed.
21
+
22
+ However,keep in mind that marking a relationship as `async: false` will introduce
23
+ bugs into your application if the data is not always guaranteed to be available
24
+ by the time the relationship is accessed. Ergo, it is recommended when using this
25
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
26
+
27
+ Reference APIs are entangled with the relationship's underlying state,
28
+ thus any getters or cached properties that utilize these will properly
29
+ invalidate if the relationship state changes.
30
+
31
+ References are "stable", meaning that multiple calls to retrieve the reference
32
+ for a given relationship will always return the same HasManyReference.
33
+
34
+ @class BelongsToReference
35
+ @public
36
+ */
37
+ export default class BelongsToReference<T = unknown, K extends string = IsUnknown<T> extends true ? string : keyof T & string, Related = K extends keyof T ? Awaited<T[K]> : unknown> {
38
+ graph: Graph;
39
+ store: Store;
40
+ belongsToRelationship: ResourceEdge;
41
+ /**
42
+ * The field name on the parent record for this has-many relationship.
43
+ *
44
+ * @property {String} key
45
+ * @public
46
+ */
47
+ key: K;
48
+ /**
49
+ * The type of resource this relationship will contain.
50
+ *
51
+ * @property {String} type
52
+ * @public
53
+ */
54
+ type: TypeFromInstanceOrString<Related>;
55
+ ___token: object;
56
+ ___identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>;
57
+ ___relatedToken: object | null;
58
+ _ref: number;
59
+ constructor(store: Store, graph: Graph, parentIdentifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>, belongsToRelationship: ResourceEdge, key: K);
60
+ destroy(): void;
61
+ /**
62
+ * The identifier of the record that this reference refers to.
63
+ * `null` if no related record is known.
64
+ *
65
+ * @property {StableRecordIdentifier | null} identifier
66
+ * @public
67
+ */
68
+ get identifier(): StableRecordIdentifier<TypeFromInstanceOrString<Related>> | null;
69
+ /**
70
+ The `id` of the record that this reference refers to. Together, the
71
+ `type()` and `id()` methods form a composite key for the identity
72
+ map. This can be used to access the id of an async relationship
73
+ without triggering a fetch that would normally happen if you
74
+ attempted to use `record.relationship.id`.
75
+
76
+ Example
77
+
78
+ ```javascript
79
+ // models/blog.js
80
+ import Model, { belongsTo } from '@ember-data/model';
81
+
82
+ export default class BlogModel extends Model {
83
+ @belongsTo('user', { async: true, inverse: null }) user;
84
+ }
85
+
86
+ let blog = store.push({
87
+ data: {
88
+ type: 'blog',
89
+ id: 1,
90
+ relationships: {
91
+ user: {
92
+ data: { type: 'user', id: 1 }
93
+ }
92
94
  }
93
95
  }
96
+ });
97
+ let userRef = blog.belongsTo('user');
98
+
99
+ // get the identifier of the reference
100
+ if (userRef.remoteType() === "id") {
101
+ let id = userRef.id();
94
102
  }
95
- });
96
- let userRef = blog.belongsTo('user');
97
-
98
- // get the identifier of the reference
99
- if (userRef.remoteType() === "id") {
100
- let id = userRef.id();
101
- }
102
- ```
103
-
104
- @method id
105
- @public
106
- @return {String} The id of the record in this belongsTo relationship.
107
- */
108
- id(): string | null;
109
- /**
110
- The link Ember Data will use to fetch or reload this belongs-to
111
- relationship. By default it uses only the "related" resource linkage.
112
-
113
- Example
114
-
115
- ```javascript
116
- // models/blog.js
117
- import Model, { belongsTo } from '@ember-data/model';
118
- export default Model.extend({
119
- user: belongsTo('user', { async: true, inverse: null })
120
- });
121
-
122
- let blog = store.push({
123
- data: {
124
- type: 'blog',
125
- id: 1,
126
- relationships: {
127
- user: {
128
- links: {
129
- related: '/articles/1/author'
103
+ ```
104
+
105
+ @method id
106
+ @public
107
+ @return {String} The id of the record in this belongsTo relationship.
108
+ */
109
+ id(): string | null;
110
+ /**
111
+ The link Ember Data will use to fetch or reload this belongs-to
112
+ relationship. By default it uses only the "related" resource linkage.
113
+
114
+ Example
115
+
116
+ ```javascript
117
+ // models/blog.js
118
+ import Model, { belongsTo } from '@ember-data/model';
119
+ export default Model.extend({
120
+ user: belongsTo('user', { async: true, inverse: null })
121
+ });
122
+
123
+ let blog = store.push({
124
+ data: {
125
+ type: 'blog',
126
+ id: 1,
127
+ relationships: {
128
+ user: {
129
+ links: {
130
+ related: '/articles/1/author'
131
+ }
130
132
  }
131
133
  }
132
134
  }
135
+ });
136
+ let userRef = blog.belongsTo('user');
137
+
138
+ // get the identifier of the reference
139
+ if (userRef.remoteType() === "link") {
140
+ let link = userRef.link();
133
141
  }
134
- });
135
- let userRef = blog.belongsTo('user');
136
-
137
- // get the identifier of the reference
138
- if (userRef.remoteType() === "link") {
139
- let link = userRef.link();
140
- }
141
- ```
142
-
143
- @method link
144
- @public
145
- @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
146
- */
147
- link(): string | null;
148
- /**
149
- * any links that have been received for this relationship
150
- *
151
- * @method links
152
- * @public
153
- * @return
154
- */
155
- links(): Links | null;
156
- /**
157
- The meta data for the belongs-to relationship.
158
-
159
- Example
160
-
161
- ```javascript
162
- // models/blog.js
163
- import Model, { belongsTo } from '@ember-data/model';
164
- export default Model.extend({
165
- user: belongsTo('user', { async: true, inverse: null })
166
- });
167
-
168
- let blog = store.push({
169
- data: {
170
- type: 'blog',
171
- id: 1,
172
- relationships: {
173
- user: {
174
- links: {
175
- related: {
176
- href: '/articles/1/author'
142
+ ```
143
+
144
+ @method link
145
+ @public
146
+ @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
147
+ */
148
+ link(): string | null;
149
+ /**
150
+ * any links that have been received for this relationship
151
+ *
152
+ * @method links
153
+ * @public
154
+ * @return
155
+ */
156
+ links(): Links | null;
157
+ /**
158
+ The meta data for the belongs-to relationship.
159
+
160
+ Example
161
+
162
+ ```javascript
163
+ // models/blog.js
164
+ import Model, { belongsTo } from '@ember-data/model';
165
+ export default Model.extend({
166
+ user: belongsTo('user', { async: true, inverse: null })
167
+ });
168
+
169
+ let blog = store.push({
170
+ data: {
171
+ type: 'blog',
172
+ id: 1,
173
+ relationships: {
174
+ user: {
175
+ links: {
176
+ related: {
177
+ href: '/articles/1/author'
178
+ },
177
179
  },
178
- },
179
- meta: {
180
- lastUpdated: 1458014400000
180
+ meta: {
181
+ lastUpdated: 1458014400000
182
+ }
181
183
  }
182
184
  }
183
185
  }
184
- }
185
- });
186
-
187
- let userRef = blog.belongsTo('user');
188
-
189
- userRef.meta() // { lastUpdated: 1458014400000 }
190
- ```
191
-
192
- @method meta
193
- @public
194
- @return {Object} The meta information for the belongs-to relationship.
195
- */
196
- meta(): Meta | null;
197
- _resource(): SingleResourceRelationship;
198
- /**
199
- This returns a string that represents how the reference will be
200
- looked up when it is loaded. If the relationship has a link it will
201
- use the "link" otherwise it defaults to "id".
202
-
203
- Example
204
-
205
- ```app/models/post.js
206
- import Model, { hasMany } from '@ember-data/model';
207
-
208
- export default class PostModel extends Model {
209
- @hasMany('comment', { async: true, inverse: null }) comments;
210
- }
211
- ```
212
-
213
- ```javascript
214
- let post = store.push({
215
- data: {
216
- type: 'post',
217
- id: 1,
218
- relationships: {
219
- comments: {
220
- data: [{ type: 'comment', id: 1 }]
186
+ });
187
+
188
+ let userRef = blog.belongsTo('user');
189
+
190
+ userRef.meta() // { lastUpdated: 1458014400000 }
191
+ ```
192
+
193
+ @method meta
194
+ @public
195
+ @return {Object} The meta information for the belongs-to relationship.
196
+ */
197
+ meta(): Meta | null;
198
+ _resource(): SingleResourceRelationship;
199
+ /**
200
+ This returns a string that represents how the reference will be
201
+ looked up when it is loaded. If the relationship has a link it will
202
+ use the "link" otherwise it defaults to "id".
203
+
204
+ Example
205
+
206
+ ```app/models/post.js
207
+ import Model, { hasMany } from '@ember-data/model';
208
+
209
+ export default class PostModel extends Model {
210
+ @hasMany('comment', { async: true, inverse: null }) comments;
211
+ }
212
+ ```
213
+
214
+ ```javascript
215
+ let post = store.push({
216
+ data: {
217
+ type: 'post',
218
+ id: 1,
219
+ relationships: {
220
+ comments: {
221
+ data: [{ type: 'comment', id: 1 }]
222
+ }
221
223
  }
222
224
  }
225
+ });
226
+
227
+ let commentsRef = post.hasMany('comments');
228
+
229
+ // get the identifier of the reference
230
+ if (commentsRef.remoteType() === "ids") {
231
+ let ids = commentsRef.ids();
232
+ } else if (commentsRef.remoteType() === "link") {
233
+ let link = commentsRef.link();
223
234
  }
224
- });
225
-
226
- let commentsRef = post.hasMany('comments');
227
-
228
- // get the identifier of the reference
229
- if (commentsRef.remoteType() === "ids") {
230
- let ids = commentsRef.ids();
231
- } else if (commentsRef.remoteType() === "link") {
232
- let link = commentsRef.link();
233
- }
234
- ```
235
-
236
- @method remoteType
237
- @public
238
- @return {String} The name of the remote type. This should either be `link` or `id`
239
- */
240
- remoteType(): 'link' | 'id';
241
- /**
242
- `push` can be used to update the data in the relationship and EmberData
243
- will treat the new data as the canonical value of this relationship on
244
- the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
245
- clear the relationship.
246
-
247
- Example model
248
-
249
- ```app/models/blog.js
250
- import Model, { belongsTo } from '@ember-data/model';
251
-
252
- export default class BlogModel extends Model {
253
- @belongsTo('user', { async: true, inverse: null }) user;
254
- }
255
- ```
256
-
257
- Setup some initial state, note we haven't loaded the user yet:
258
-
259
- ```js
260
- const blog = store.push({
261
- data: {
262
- type: 'blog',
263
- id: '1',
264
- relationships: {
265
- user: {
266
- data: { type: 'user', id: '1' }
235
+ ```
236
+
237
+ @method remoteType
238
+ @public
239
+ @return {String} The name of the remote type. This should either be `link` or `id`
240
+ */
241
+ remoteType(): 'link' | 'id';
242
+ /**
243
+ `push` can be used to update the data in the relationship and EmberData
244
+ will treat the new data as the canonical value of this relationship on
245
+ the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
246
+ clear the relationship.
247
+
248
+ Example model
249
+
250
+ ```app/models/blog.js
251
+ import Model, { belongsTo } from '@ember-data/model';
252
+
253
+ export default class BlogModel extends Model {
254
+ @belongsTo('user', { async: true, inverse: null }) user;
255
+ }
256
+ ```
257
+
258
+ Setup some initial state, note we haven't loaded the user yet:
259
+
260
+ ```js
261
+ const blog = store.push({
262
+ data: {
263
+ type: 'blog',
264
+ id: '1',
265
+ relationships: {
266
+ user: {
267
+ data: { type: 'user', id: '1' }
268
+ }
267
269
  }
268
270
  }
269
- }
270
- });
271
-
272
- const userRef = blog.belongsTo('user');
273
- userRef.id(); // '1'
274
- ```
275
-
276
- Update the state using `push`, note we can do this even without
277
- having loaded the user yet by providing a resource-identifier.
278
-
279
- Both full a resource and a resource-identifier are supported.
280
-
281
- ```js
282
- await userRef.push({
283
- data: {
284
- type: 'user',
285
- id: '2',
286
- }
287
- });
288
-
289
- userRef.id(); // '2'
290
- ```
291
-
292
- You may also pass in links and meta fore the relationship, and sideload
293
- additional resources that might be required.
294
-
295
- ```js
296
- await userRef.push({
271
+ });
272
+
273
+ const userRef = blog.belongsTo('user');
274
+ userRef.id(); // '1'
275
+ ```
276
+
277
+ Update the state using `push`, note we can do this even without
278
+ having loaded the user yet by providing a resource-identifier.
279
+
280
+ Both full a resource and a resource-identifier are supported.
281
+
282
+ ```js
283
+ await userRef.push({
297
284
  data: {
298
285
  type: 'user',
299
286
  id: '2',
300
- },
301
- links: {
302
- related: '/articles/1/author'
303
- },
304
- meta: {
305
- lastUpdated: Date.now()
306
- },
307
- included: [
308
- {
309
- type: 'user-preview',
287
+ }
288
+ });
289
+
290
+ userRef.id(); // '2'
291
+ ```
292
+
293
+ You may also pass in links and meta fore the relationship, and sideload
294
+ additional resources that might be required.
295
+
296
+ ```js
297
+ await userRef.push({
298
+ data: {
299
+ type: 'user',
310
300
  id: '2',
311
- attributes: {
312
- username: '@runspired'
301
+ },
302
+ links: {
303
+ related: '/articles/1/author'
304
+ },
305
+ meta: {
306
+ lastUpdated: Date.now()
307
+ },
308
+ included: [
309
+ {
310
+ type: 'user-preview',
311
+ id: '2',
312
+ attributes: {
313
+ username: '@runspired'
314
+ }
315
+ }
316
+ ]
317
+ });
318
+ ```
319
+
320
+ By default, the store will attempt to fetch the record if it is not loaded or its
321
+ resource data is not included in the call to `push` before resolving the returned
322
+ promise with the new state..
323
+
324
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
325
+ and instead the promise will resolve with void without attempting to fetch. This is
326
+ particularly useful if you want to update the state of the relationship without
327
+ forcing the load of all of the associated record.
328
+
329
+ @method push
330
+ @public
331
+ @param {Object} doc a JSONAPI document object describing the new value of this relationship.
332
+ @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
333
+ @return {Promise<OpaqueRecordInstance | null | void>}
334
+ */
335
+ push(doc: SingleResourceDocument, skipFetch?: boolean): Promise<Related | null | void>;
336
+ /**
337
+ `value()` synchronously returns the current value of the belongs-to
338
+ relationship. Unlike `record.relationshipName`, calling
339
+ `value()` on a reference does not trigger a fetch if the async
340
+ relationship is not yet loaded. If the relationship is not loaded
341
+ it will always return `null`.
342
+
343
+ Example
344
+
345
+ ```javascript
346
+ // models/blog.js
347
+ import Model, { belongsTo } from '@ember-data/model';
348
+
349
+ export default class BlogModel extends Model {
350
+ @belongsTo('user', { async: true, inverse: null }) user;
351
+ }
352
+
353
+ let blog = store.push({
354
+ data: {
355
+ type: 'blog',
356
+ id: 1,
357
+ relationships: {
358
+ user: {
359
+ data: { type: 'user', id: 1 }
313
360
  }
314
361
  }
315
- ]
362
+ }
316
363
  });
317
- ```
318
-
319
- By default, the store will attempt to fetch the record if it is not loaded or its
320
- resource data is not included in the call to `push` before resolving the returned
321
- promise with the new state..
322
-
323
- Alternatively, pass `true` as the second argument to avoid fetching unloaded records
324
- and instead the promise will resolve with void without attempting to fetch. This is
325
- particularly useful if you want to update the state of the relationship without
326
- forcing the load of all of the associated record.
327
-
328
- @method push
329
- @public
330
- @param {Object} doc a JSONAPI document object describing the new value of this relationship.
331
- @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
332
- @return {Promise<OpaqueRecordInstance | null | void>}
333
- */
334
- push(doc: SingleResourceDocument, skipFetch?: boolean): Promise<Related | null | void>;
335
- /**
336
- `value()` synchronously returns the current value of the belongs-to
337
- relationship. Unlike `record.relationshipName`, calling
338
- `value()` on a reference does not trigger a fetch if the async
339
- relationship is not yet loaded. If the relationship is not loaded
340
- it will always return `null`.
341
-
342
- Example
343
-
344
- ```javascript
345
- // models/blog.js
346
- import Model, { belongsTo } from '@ember-data/model';
347
-
348
- export default class BlogModel extends Model {
349
- @belongsTo('user', { async: true, inverse: null }) user;
350
- }
351
-
352
- let blog = store.push({
353
- data: {
354
- type: 'blog',
355
- id: 1,
356
- relationships: {
357
- user: {
358
- data: { type: 'user', id: 1 }
364
+ let userRef = blog.belongsTo('user');
365
+
366
+ userRef.value(); // null
367
+
368
+ // provide data for reference
369
+ userRef.push({
370
+ data: {
371
+ type: 'user',
372
+ id: 1,
373
+ attributes: {
374
+ username: "@user"
359
375
  }
360
376
  }
361
- }
362
- });
363
- let userRef = blog.belongsTo('user');
364
-
365
- userRef.value(); // null
366
-
367
- // provide data for reference
368
- userRef.push({
369
- data: {
370
- type: 'user',
371
- id: 1,
372
- attributes: {
373
- username: "@user"
374
- }
375
- }
376
- }).then(function(user) {
377
- userRef.value(); // user
378
- });
379
- ```
380
-
381
- @method value
382
- @public
383
- @return {Model} the record in this relationship
384
- */
385
- value(): Related | null;
386
- /**
387
- Loads a record in a belongs-to relationship if it is not already
388
- loaded. If the relationship is already loaded this method does not
389
- trigger a new load.
390
-
391
- Example
392
-
393
- ```javascript
394
- // models/blog.js
395
- import Model, { belongsTo } from '@ember-data/model';
396
-
397
- export default class BlogModel extends Model {
398
- @belongsTo('user', { async: true, inverse: null }) user;
399
- }
400
-
401
- let blog = store.push({
402
- data: {
403
- type: 'blog',
404
- id: 1,
405
- relationships: {
406
- user: {
407
- data: { type: 'user', id: 1 }
377
+ }).then(function(user) {
378
+ userRef.value(); // user
379
+ });
380
+ ```
381
+
382
+ @method value
383
+ @public
384
+ @return {Model} the record in this relationship
385
+ */
386
+ value(): Related | null;
387
+ /**
388
+ Loads a record in a belongs-to relationship if it is not already
389
+ loaded. If the relationship is already loaded this method does not
390
+ trigger a new load.
391
+
392
+ Example
393
+
394
+ ```javascript
395
+ // models/blog.js
396
+ import Model, { belongsTo } from '@ember-data/model';
397
+
398
+ export default class BlogModel extends Model {
399
+ @belongsTo('user', { async: true, inverse: null }) user;
400
+ }
401
+
402
+ let blog = store.push({
403
+ data: {
404
+ type: 'blog',
405
+ id: 1,
406
+ relationships: {
407
+ user: {
408
+ data: { type: 'user', id: 1 }
409
+ }
408
410
  }
409
411
  }
410
- }
411
- });
412
- let userRef = blog.belongsTo('user');
413
-
414
- userRef.value(); // null
415
-
416
- userRef.load().then(function(user) {
417
- userRef.value() === user
418
- });
419
- ```
420
-
421
- You may also pass in an options object whose properties will be
422
- fed forward. This enables you to pass `adapterOptions` into the
423
- request given to the adapter via the reference.
424
-
425
- Example
426
-
427
- ```javascript
428
- userRef.load({ adapterOptions: { isPrivate: true } }).then(function(user) {
429
- userRef.value() === user;
430
- });
431
- ```
432
- ```app/adapters/user.js
433
- import Adapter from '@ember-data/adapter';
434
-
435
- export default class UserAdapter extends Adapter {
436
- findRecord(store, type, id, snapshot) {
437
- // In the adapter you will have access to adapterOptions.
438
- let adapterOptions = snapshot.adapterOptions;
412
+ });
413
+ let userRef = blog.belongsTo('user');
414
+
415
+ userRef.value(); // null
416
+
417
+ userRef.load().then(function(user) {
418
+ userRef.value() === user
419
+ });
420
+ ```
421
+
422
+ You may also pass in an options object whose properties will be
423
+ fed forward. This enables you to pass `adapterOptions` into the
424
+ request given to the adapter via the reference.
425
+
426
+ Example
427
+
428
+ ```javascript
429
+ userRef.load({ adapterOptions: { isPrivate: true } }).then(function(user) {
430
+ userRef.value() === user;
431
+ });
432
+ ```
433
+ ```app/adapters/user.js
434
+ import Adapter from '@ember-data/adapter';
435
+
436
+ export default class UserAdapter extends Adapter {
437
+ findRecord(store, type, id, snapshot) {
438
+ // In the adapter you will have access to adapterOptions.
439
+ let adapterOptions = snapshot.adapterOptions;
440
+ }
441
+ });
442
+ ```
443
+
444
+ @method load
445
+ @public
446
+ @param {Object} options the options to pass in.
447
+ @return {Promise} a promise that resolves with the record in this belongs-to relationship.
448
+ */
449
+ load(options?: Record<string, unknown>): Promise<Related | null>;
450
+ /**
451
+ Triggers a reload of the value in this relationship. If the
452
+ remoteType is `"link"` Ember Data will use the relationship link to
453
+ reload the relationship. Otherwise it will reload the record by its
454
+ id.
455
+
456
+ Example
457
+
458
+ ```javascript
459
+ // models/blog.js
460
+ import Model, { belongsTo } from '@ember-data/model';
461
+
462
+ export default class BlogModel extends Model {
463
+ @belongsTo('user', { async: true, inverse: null }) user;
439
464
  }
440
- });
441
- ```
442
-
443
- @method load
444
- @public
445
- @param {Object} options the options to pass in.
446
- @return {Promise} a promise that resolves with the record in this belongs-to relationship.
447
- */
448
- load(options?: Record<string, unknown>): Promise<Related | null>;
449
- /**
450
- Triggers a reload of the value in this relationship. If the
451
- remoteType is `"link"` Ember Data will use the relationship link to
452
- reload the relationship. Otherwise it will reload the record by its
453
- id.
454
-
455
- Example
456
-
457
- ```javascript
458
- // models/blog.js
459
- import Model, { belongsTo } from '@ember-data/model';
460
-
461
- export default class BlogModel extends Model {
462
- @belongsTo('user', { async: true, inverse: null }) user;
463
- }
464
-
465
- let blog = store.push({
466
- data: {
467
- type: 'blog',
468
- id: 1,
469
- relationships: {
470
- user: {
471
- data: { type: 'user', id: 1 }
465
+
466
+ let blog = store.push({
467
+ data: {
468
+ type: 'blog',
469
+ id: 1,
470
+ relationships: {
471
+ user: {
472
+ data: { type: 'user', id: 1 }
473
+ }
472
474
  }
473
475
  }
474
- }
475
- });
476
- let userRef = blog.belongsTo('user');
477
-
478
- userRef.reload().then(function(user) {
479
- userRef.value() === user
480
- });
481
- ```
482
-
483
- You may also pass in an options object whose properties will be
484
- fed forward. This enables you to pass `adapterOptions` into the
485
- request given to the adapter via the reference. A full example
486
- can be found in the `load` method.
487
-
488
- Example
489
-
490
- ```javascript
491
- userRef.reload({ adapterOptions: { isPrivate: true } })
492
- ```
493
-
494
- @method reload
495
- @public
496
- @param {Object} options the options to pass in.
497
- @return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed.
498
- */
499
- reload(options?: Record<string, unknown>): Promise<Related | null>;
476
+ });
477
+ let userRef = blog.belongsTo('user');
478
+
479
+ userRef.reload().then(function(user) {
480
+ userRef.value() === user
481
+ });
482
+ ```
483
+
484
+ You may also pass in an options object whose properties will be
485
+ fed forward. This enables you to pass `adapterOptions` into the
486
+ request given to the adapter via the reference. A full example
487
+ can be found in the `load` method.
488
+
489
+ Example
490
+
491
+ ```javascript
492
+ userRef.reload({ adapterOptions: { isPrivate: true } })
493
+ ```
494
+
495
+ @method reload
496
+ @public
497
+ @param {Object} options the options to pass in.
498
+ @return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed.
499
+ */
500
+ reload(options?: Record<string, unknown>): Promise<Related | null>;
501
+ }
500
502
  }
501
503
  //# sourceMappingURL=belongs-to.d.ts.map