@ember-data/store 4.5.0-beta.0 → 4.5.0
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.
- package/addon/-private/{system/backburner.js → backburner.js} +0 -0
- package/addon/-private/{system/coerce-id.ts → coerce-id.ts} +0 -0
- package/addon/-private/{system/store/common.js → common.js} +0 -0
- package/addon/-private/{system/core-store.ts → core-store.ts} +467 -1253
- package/addon/-private/{system/errors-utils.js → errors-utils.js} +7 -6
- package/addon/-private/{system/fetch-manager.ts → fetch-manager.ts} +72 -42
- package/addon/-private/finders.js +107 -0
- package/addon/-private/identifer-debug-consts.ts +3 -0
- package/addon/-private/{identifiers/cache.ts → identifier-cache.ts} +26 -14
- package/addon/-private/{system/identity-map.ts → identity-map.ts} +2 -1
- package/addon/-private/index.ts +17 -17
- package/addon/-private/instance-cache.ts +387 -0
- package/addon/-private/{system/store/internal-model-factory.ts → internal-model-factory.ts} +25 -19
- package/addon/-private/{system/internal-model-map.ts → internal-model-map.ts} +9 -5
- package/addon/-private/model/internal-model.ts +602 -0
- package/addon/-private/{system/references/record.ts → model/record-reference.ts} +23 -36
- package/addon/-private/{system/model → model}/shim-model-class.ts +19 -14
- package/addon/-private/{system/normalize-model-name.ts → normalize-model-name.ts} +0 -0
- package/addon/-private/{system/promise-proxies.ts → promise-proxies.ts} +12 -5
- package/addon/-private/{system/promise-proxy-base.js → promise-proxy-base.js} +0 -0
- package/addon/-private/{system/record-array-manager.ts → record-array-manager.ts} +19 -18
- package/addon/-private/{system/record-arrays → record-arrays}/adapter-populated-record-array.ts +11 -10
- package/addon/-private/{system/record-arrays → record-arrays}/record-array.ts +37 -19
- package/addon/-private/record-data-for.ts +39 -0
- package/addon/-private/{system/store/record-data-store-wrapper.ts → record-data-store-wrapper.ts} +21 -26
- package/addon/-private/{system/record-notification-manager.ts → record-notification-manager.ts} +8 -3
- package/addon/-private/{system/request-cache.ts → request-cache.ts} +5 -6
- package/addon/-private/{system/schema-definition-service.ts → schema-definition-service.ts} +30 -14
- package/addon/-private/{system/store/serializer-response.ts → serializer-response.ts} +7 -6
- package/addon/-private/{system/snapshot-record-array.ts → snapshot-record-array.ts} +27 -8
- package/addon/-private/{system/snapshot.ts → snapshot.ts} +54 -39
- package/addon/-private/utils/construct-resource.ts +7 -3
- package/addon/-private/utils/promise-record.ts +9 -18
- package/addon/-private/{system/weak-cache.ts → weak-cache.ts} +2 -2
- package/addon/index.ts +1 -0
- package/package.json +21 -20
- package/addon/-private/identifiers/is-stable-identifier.ts +0 -18
- package/addon/-private/identifiers/utils/uuid-v4.ts +0 -80
- package/addon/-private/system/ds-model-store.ts +0 -136
- package/addon/-private/system/model/internal-model.ts +0 -1303
- package/addon/-private/system/model/states.js +0 -736
- package/addon/-private/system/record-arrays.ts +0 -8
- package/addon/-private/system/record-data-for.ts +0 -54
- package/addon/-private/system/references/belongs-to.ts +0 -406
- package/addon/-private/system/references/has-many.ts +0 -487
- package/addon/-private/system/references/reference.ts +0 -205
- package/addon/-private/system/references.js +0 -9
- package/addon/-private/system/store/finders.js +0 -412
- package/addon/-private/ts-interfaces/ds-model.ts +0 -50
- package/addon/-private/ts-interfaces/ember-data-json-api.ts +0 -145
- package/addon/-private/ts-interfaces/fetch-manager.ts +0 -44
- package/addon/-private/ts-interfaces/identifier.ts +0 -246
- package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +0 -584
- package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +0 -257
- package/addon/-private/ts-interfaces/promise-proxies.ts +0 -3
- package/addon/-private/ts-interfaces/record-data-json-api.ts +0 -29
- package/addon/-private/ts-interfaces/record-data-record-wrapper.ts +0 -46
- package/addon/-private/ts-interfaces/record-data-schemas.ts +0 -45
- package/addon/-private/ts-interfaces/record-data-store-wrapper.ts +0 -56
- package/addon/-private/ts-interfaces/record-data.ts +0 -72
- package/addon/-private/ts-interfaces/record-instance.ts +0 -18
- package/addon/-private/ts-interfaces/schema-definition-service.ts +0 -12
- package/addon/-private/ts-interfaces/store.ts +0 -10
- package/addon/-private/ts-interfaces/utils.ts +0 -6
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { assert } from '@ember/debug';
|
|
2
|
-
import { DEBUG } from '@glimmer/env';
|
|
3
|
-
|
|
4
|
-
import type { StableRecordIdentifier } from '../ts-interfaces/identifier';
|
|
5
|
-
import type { RecordData } from '../ts-interfaces/record-data';
|
|
6
|
-
import type { RecordInstance } from '../ts-interfaces/record-instance';
|
|
7
|
-
import WeakCache from './weak-cache';
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
* Returns the RecordData instance associated with a given
|
|
11
|
-
* Model or InternalModel.
|
|
12
|
-
*
|
|
13
|
-
* Intentionally "loose" to allow anything with an _internalModel
|
|
14
|
-
* property until InternalModel is eliminated.
|
|
15
|
-
*
|
|
16
|
-
* Intentionally not typed to `InternalModel` due to circular dependency
|
|
17
|
-
* which that creates.
|
|
18
|
-
*
|
|
19
|
-
* Overtime, this should shift to a "weakmap" based lookup in the
|
|
20
|
-
* "Ember.getOwner(obj)" style.
|
|
21
|
-
*/
|
|
22
|
-
interface InternalModel {
|
|
23
|
-
_recordData: RecordData;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type DSModelOrSnapshot = { _internalModel: InternalModel };
|
|
27
|
-
type Reference = { internalModel: InternalModel };
|
|
28
|
-
|
|
29
|
-
type Instance = StableRecordIdentifier | InternalModel | RecordData | DSModelOrSnapshot | Reference;
|
|
30
|
-
|
|
31
|
-
const RecordDataForIdentifierCache = new WeakCache<StableRecordIdentifier, RecordData>(DEBUG ? 'recordData' : '');
|
|
32
|
-
|
|
33
|
-
export function setRecordDataFor(identifier: StableRecordIdentifier, recordData: RecordData): void {
|
|
34
|
-
assert(`Illegal set of identifier`, !RecordDataForIdentifierCache.has(identifier));
|
|
35
|
-
RecordDataForIdentifierCache.set(identifier, recordData);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function removeRecordDataFor(identifier: StableRecordIdentifier): void {
|
|
39
|
-
RecordDataForIdentifierCache.delete(identifier);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default function recordDataFor(instance: StableRecordIdentifier): RecordData | null;
|
|
43
|
-
export default function recordDataFor(instance: Instance): RecordData;
|
|
44
|
-
export default function recordDataFor(instance: RecordInstance): RecordData;
|
|
45
|
-
export default function recordDataFor(instance: object): null;
|
|
46
|
-
export default function recordDataFor(instance: Instance | object): RecordData | null {
|
|
47
|
-
if (RecordDataForIdentifierCache.has(instance as StableRecordIdentifier)) {
|
|
48
|
-
return RecordDataForIdentifierCache.get(instance as StableRecordIdentifier) as RecordData;
|
|
49
|
-
}
|
|
50
|
-
let internalModel =
|
|
51
|
-
(instance as DSModelOrSnapshot)._internalModel || (instance as Reference).internalModel || instance;
|
|
52
|
-
|
|
53
|
-
return internalModel._recordData || null;
|
|
54
|
-
}
|
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
import { dependentKeyCompat } from '@ember/object/compat';
|
|
2
|
-
import { cached, tracked } from '@glimmer/tracking';
|
|
3
|
-
|
|
4
|
-
import { resolve } from 'rsvp';
|
|
5
|
-
|
|
6
|
-
import type { BelongsToRelationship } from '@ember-data/record-data/-private';
|
|
7
|
-
import { assertPolymorphicType } from '@ember-data/store/-debug';
|
|
8
|
-
|
|
9
|
-
import { SingleResourceDocument } from '../../ts-interfaces/ember-data-json-api';
|
|
10
|
-
import { StableRecordIdentifier } from '../../ts-interfaces/identifier';
|
|
11
|
-
import { RecordInstance } from '../../ts-interfaces/record-instance';
|
|
12
|
-
import CoreStore from '../core-store';
|
|
13
|
-
import { NotificationType, unsubscribe } from '../record-notification-manager';
|
|
14
|
-
import { internalModelFactoryFor, recordIdentifierFor } from '../store/internal-model-factory';
|
|
15
|
-
import RecordReference from './record';
|
|
16
|
-
import Reference from './reference';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
@module @ember-data/store
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
A `BelongsToReference` is a low-level API that allows users and
|
|
24
|
-
addon authors to perform meta-operations on a belongs-to
|
|
25
|
-
relationship.
|
|
26
|
-
|
|
27
|
-
@class BelongsToReference
|
|
28
|
-
@public
|
|
29
|
-
@extends Reference
|
|
30
|
-
*/
|
|
31
|
-
export default class BelongsToReference extends Reference {
|
|
32
|
-
declare key: string;
|
|
33
|
-
declare belongsToRelationship: BelongsToRelationship;
|
|
34
|
-
declare type: string;
|
|
35
|
-
declare parent: RecordReference;
|
|
36
|
-
declare parentIdentifier: StableRecordIdentifier;
|
|
37
|
-
|
|
38
|
-
// unsubscribe tokens given to us by the notification manager
|
|
39
|
-
#token!: Object;
|
|
40
|
-
#relatedToken: Object | null = null;
|
|
41
|
-
|
|
42
|
-
@tracked _ref = 0;
|
|
43
|
-
|
|
44
|
-
constructor(
|
|
45
|
-
store: CoreStore,
|
|
46
|
-
parentIdentifier: StableRecordIdentifier,
|
|
47
|
-
belongsToRelationship: BelongsToRelationship,
|
|
48
|
-
key: string
|
|
49
|
-
) {
|
|
50
|
-
super(store, parentIdentifier);
|
|
51
|
-
this.key = key;
|
|
52
|
-
this.belongsToRelationship = belongsToRelationship;
|
|
53
|
-
this.type = belongsToRelationship.definition.type;
|
|
54
|
-
const parent = internalModelFactoryFor(store).peek(parentIdentifier);
|
|
55
|
-
this.parent = parent!.recordReference;
|
|
56
|
-
this.parentIdentifier = parentIdentifier;
|
|
57
|
-
|
|
58
|
-
this.#token = store._notificationManager.subscribe(
|
|
59
|
-
parentIdentifier,
|
|
60
|
-
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
61
|
-
if ((bucket === 'relationships' || bucket === 'property') && notifiedKey === key) {
|
|
62
|
-
this._ref++;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
// TODO inverse
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
destroy() {
|
|
71
|
-
unsubscribe(this.#token);
|
|
72
|
-
if (this.#relatedToken) {
|
|
73
|
-
unsubscribe(this.#relatedToken);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@cached
|
|
78
|
-
@dependentKeyCompat
|
|
79
|
-
get _relatedIdentifier(): StableRecordIdentifier | null {
|
|
80
|
-
this._ref; // consume the tracked prop
|
|
81
|
-
if (this.#relatedToken) {
|
|
82
|
-
unsubscribe(this.#relatedToken);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let resource = this._resource();
|
|
86
|
-
if (resource && resource.data) {
|
|
87
|
-
const identifier = this.store.identifierCache.getOrCreateRecordIdentifier(resource.data);
|
|
88
|
-
this.#relatedToken = this.store._notificationManager.subscribe(
|
|
89
|
-
identifier,
|
|
90
|
-
(_: StableRecordIdentifier, bucket: NotificationType, notifiedKey?: string) => {
|
|
91
|
-
if (bucket === 'identity' || ((bucket === 'attributes' || bucket === 'property') && notifiedKey === 'id')) {
|
|
92
|
-
this._ref++;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return identifier;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
The `id` of the record that this reference refers to. Together, the
|
|
105
|
-
`type()` and `id()` methods form a composite key for the identity
|
|
106
|
-
map. This can be used to access the id of an async relationship
|
|
107
|
-
without triggering a fetch that would normally happen if you
|
|
108
|
-
attempted to use `record.get('relationship.id')`.
|
|
109
|
-
|
|
110
|
-
Example
|
|
111
|
-
|
|
112
|
-
```javascript
|
|
113
|
-
// models/blog.js
|
|
114
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
115
|
-
|
|
116
|
-
export default class BlogModel extends Model {
|
|
117
|
-
@belongsTo({ async: true }) user;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
let blog = store.push({
|
|
121
|
-
data: {
|
|
122
|
-
type: 'blog',
|
|
123
|
-
id: 1,
|
|
124
|
-
relationships: {
|
|
125
|
-
user: {
|
|
126
|
-
data: { type: 'user', id: 1 }
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
let userRef = blog.belongsTo('user');
|
|
132
|
-
|
|
133
|
-
// get the identifier of the reference
|
|
134
|
-
if (userRef.remoteType() === "id") {
|
|
135
|
-
let id = userRef.id();
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
@method id
|
|
140
|
-
@public
|
|
141
|
-
@return {String} The id of the record in this belongsTo relationship.
|
|
142
|
-
*/
|
|
143
|
-
id(): string | null {
|
|
144
|
-
return this._relatedIdentifier?.id || null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
_resource() {
|
|
148
|
-
return this.recordData.getBelongsTo(this.key);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
`push` can be used to update the data in the relationship and Ember
|
|
153
|
-
Data will treat the new data as the canonical value of this
|
|
154
|
-
relationship on the backend.
|
|
155
|
-
|
|
156
|
-
Example
|
|
157
|
-
|
|
158
|
-
```app/models/blog.js
|
|
159
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
160
|
-
|
|
161
|
-
export default class BlogModel extends Model {
|
|
162
|
-
@belongsTo({ async: true }) user;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
let blog = store.push({
|
|
166
|
-
data: {
|
|
167
|
-
type: 'blog',
|
|
168
|
-
id: 1,
|
|
169
|
-
relationships: {
|
|
170
|
-
user: {
|
|
171
|
-
data: { type: 'user', id: 1 }
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
let userRef = blog.belongsTo('user');
|
|
177
|
-
|
|
178
|
-
// provide data for reference
|
|
179
|
-
userRef.push({
|
|
180
|
-
data: {
|
|
181
|
-
type: 'user',
|
|
182
|
-
id: 1,
|
|
183
|
-
attributes: {
|
|
184
|
-
username: "@user"
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}).then(function(user) {
|
|
188
|
-
userRef.value() === user;
|
|
189
|
-
});
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
@method push
|
|
193
|
-
@public
|
|
194
|
-
@param {Object|Promise} objectOrPromise a promise that resolves to a JSONAPI document object describing the new value of this relationship.
|
|
195
|
-
@return {Promise<record>} A promise that resolves with the new value in this belongs-to relationship.
|
|
196
|
-
*/
|
|
197
|
-
async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<RecordInstance> {
|
|
198
|
-
const jsonApiDoc = await resolve(data);
|
|
199
|
-
let record = this.store.push(jsonApiDoc);
|
|
200
|
-
|
|
201
|
-
assertPolymorphicType(
|
|
202
|
-
this.belongsToRelationship.identifier,
|
|
203
|
-
this.belongsToRelationship.definition,
|
|
204
|
-
recordIdentifierFor(record),
|
|
205
|
-
this.store
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
const { graph, identifier } = this.belongsToRelationship;
|
|
209
|
-
this.store._backburner.join(() => {
|
|
210
|
-
graph.push({
|
|
211
|
-
op: 'replaceRelatedRecord',
|
|
212
|
-
record: identifier,
|
|
213
|
-
field: this.key,
|
|
214
|
-
value: recordIdentifierFor(record),
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
return record;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
`value()` synchronously returns the current value of the belongs-to
|
|
223
|
-
relationship. Unlike `record.get('relationshipName')`, calling
|
|
224
|
-
`value()` on a reference does not trigger a fetch if the async
|
|
225
|
-
relationship is not yet loaded. If the relationship is not loaded
|
|
226
|
-
it will always return `null`.
|
|
227
|
-
|
|
228
|
-
Example
|
|
229
|
-
|
|
230
|
-
```javascript
|
|
231
|
-
// models/blog.js
|
|
232
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
233
|
-
|
|
234
|
-
export default class BlogModel extends Model {
|
|
235
|
-
@belongsTo({ async: true }) user;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
let blog = store.push({
|
|
239
|
-
data: {
|
|
240
|
-
type: 'blog',
|
|
241
|
-
id: 1,
|
|
242
|
-
relationships: {
|
|
243
|
-
user: {
|
|
244
|
-
data: { type: 'user', id: 1 }
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
let userRef = blog.belongsTo('user');
|
|
250
|
-
|
|
251
|
-
userRef.value(); // null
|
|
252
|
-
|
|
253
|
-
// provide data for reference
|
|
254
|
-
userRef.push({
|
|
255
|
-
data: {
|
|
256
|
-
type: 'user',
|
|
257
|
-
id: 1,
|
|
258
|
-
attributes: {
|
|
259
|
-
username: "@user"
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}).then(function(user) {
|
|
263
|
-
userRef.value(); // user
|
|
264
|
-
});
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
@method value
|
|
268
|
-
@public
|
|
269
|
-
@return {Model} the record in this relationship
|
|
270
|
-
*/
|
|
271
|
-
value(): RecordInstance | null {
|
|
272
|
-
let resource = this._resource();
|
|
273
|
-
if (resource && resource.data) {
|
|
274
|
-
let inverseInternalModel = this.store._internalModelForResource(resource.data);
|
|
275
|
-
if (inverseInternalModel && inverseInternalModel.currentState.isLoaded) {
|
|
276
|
-
return inverseInternalModel.getRecord();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
Loads a record in a belongs-to relationship if it is not already
|
|
285
|
-
loaded. If the relationship is already loaded this method does not
|
|
286
|
-
trigger a new load.
|
|
287
|
-
|
|
288
|
-
Example
|
|
289
|
-
|
|
290
|
-
```javascript
|
|
291
|
-
// models/blog.js
|
|
292
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
293
|
-
|
|
294
|
-
export default class BlogModel extends Model {
|
|
295
|
-
@belongsTo({ async: true }) user;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
let blog = store.push({
|
|
299
|
-
data: {
|
|
300
|
-
type: 'blog',
|
|
301
|
-
id: 1,
|
|
302
|
-
relationships: {
|
|
303
|
-
user: {
|
|
304
|
-
data: { type: 'user', id: 1 }
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
let userRef = blog.belongsTo('user');
|
|
310
|
-
|
|
311
|
-
userRef.value(); // null
|
|
312
|
-
|
|
313
|
-
userRef.load().then(function(user) {
|
|
314
|
-
userRef.value() === user
|
|
315
|
-
});
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
You may also pass in an options object whose properties will be
|
|
319
|
-
fed forward. This enables you to pass `adapterOptions` into the
|
|
320
|
-
request given to the adapter via the reference.
|
|
321
|
-
|
|
322
|
-
Example
|
|
323
|
-
|
|
324
|
-
```javascript
|
|
325
|
-
userRef.load({ adapterOptions: { isPrivate: true } }).then(function(user) {
|
|
326
|
-
userRef.value() === user;
|
|
327
|
-
});
|
|
328
|
-
```
|
|
329
|
-
```app/adapters/user.js
|
|
330
|
-
import Adapter from '@ember-data/adapter';
|
|
331
|
-
|
|
332
|
-
export default class UserAdapter extends Adapter {
|
|
333
|
-
findRecord(store, type, id, snapshot) {
|
|
334
|
-
// In the adapter you will have access to adapterOptions.
|
|
335
|
-
let adapterOptions = snapshot.adapterOptions;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
@method load
|
|
341
|
-
@public
|
|
342
|
-
@param {Object} options the options to pass in.
|
|
343
|
-
@return {Promise} a promise that resolves with the record in this belongs-to relationship.
|
|
344
|
-
*/
|
|
345
|
-
load(options) {
|
|
346
|
-
let parentInternalModel = internalModelFactoryFor(this.store).peek(this.parentIdentifier);
|
|
347
|
-
return parentInternalModel!.getBelongsTo(this.key, options);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
Triggers a reload of the value in this relationship. If the
|
|
352
|
-
remoteType is `"link"` Ember Data will use the relationship link to
|
|
353
|
-
reload the relationship. Otherwise it will reload the record by its
|
|
354
|
-
id.
|
|
355
|
-
|
|
356
|
-
Example
|
|
357
|
-
|
|
358
|
-
```javascript
|
|
359
|
-
// models/blog.js
|
|
360
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
361
|
-
|
|
362
|
-
export default class BlogModel extends Model {
|
|
363
|
-
@belongsTo({ async: true }) user;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
let blog = store.push({
|
|
367
|
-
data: {
|
|
368
|
-
type: 'blog',
|
|
369
|
-
id: 1,
|
|
370
|
-
relationships: {
|
|
371
|
-
user: {
|
|
372
|
-
data: { type: 'user', id: 1 }
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
let userRef = blog.belongsTo('user');
|
|
378
|
-
|
|
379
|
-
userRef.reload().then(function(user) {
|
|
380
|
-
userRef.value() === user
|
|
381
|
-
});
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
You may also pass in an options object whose properties will be
|
|
385
|
-
fed forward. This enables you to pass `adapterOptions` into the
|
|
386
|
-
request given to the adapter via the reference. A full example
|
|
387
|
-
can be found in the `load` method.
|
|
388
|
-
|
|
389
|
-
Example
|
|
390
|
-
|
|
391
|
-
```javascript
|
|
392
|
-
userRef.reload({ adapterOptions: { isPrivate: true } })
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
@method reload
|
|
396
|
-
@public
|
|
397
|
-
@param {Object} options the options to pass in.
|
|
398
|
-
@return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed.
|
|
399
|
-
*/
|
|
400
|
-
reload(options) {
|
|
401
|
-
let parentInternalModel = internalModelFactoryFor(this.store).peek(this.parentIdentifier);
|
|
402
|
-
return parentInternalModel!.reloadBelongsTo(this.key, options).then((internalModel) => {
|
|
403
|
-
return this.value();
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
}
|