Defined in: | addon/-private/system/references/has-many.js:16 |
---|---|
Module: | ember-data |
Defined in addon/-private/system/references/has-many.js:83
The link Ember Data will use to fetch or reload this has-many relationship.
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { links: { related: '/posts/1/comments' } } } } }); let commentsRef = post.hasMany('comments'); commentsRef.link(); // '/posts/1/comments'
Defined in addon/-private/system/references/has-many.js:365
Loads the relationship if it is not already loaded. If the relationship is already loaded this method does not trigger a new load.
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { data: [{ type: 'comment', id: 1 }] } } } }); let commentsRef = post.hasMany('comments'); commentsRef.load().then(function(comments) { //... });
Defined in addon/-private/system/references/has-many.js:162
The link Ember Data will use to fetch or reload this has-many relationship.
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { links: { related: { href: '/posts/1/comments', meta: { count: 10 } } } } } } }); let commentsRef = post.hasMany('comments'); commentsRef.meta(); // { count: 10 }
Defined in addon/-private/system/references/has-many.js:206
push
can be used to update the data in the relationship and Ember Data will treat the new data as the canonical value of this relationship on the backend.
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { data: [{ type: 'comment', id: 1 }] } } } }); let commentsRef = post.hasMany('comments'); commentsRef.ids(); // ['1'] commentsRef.push([ [{ type: 'comment', id: 2 }], [{ type: 'comment', id: 3 }], ]) commentsRef.ids(); // ['2', '3']
Defined in addon/-private/system/references/has-many.js:410
Reloads this has-many relationship.
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { data: [{ type: 'comment', id: 1 }] } } } }); let commentsRef = post.hasMany('comments'); commentsRef.reload().then(function(comments) { //... });
Defined in addon/-private/system/references/has-many.js:36
This returns a string that represents how the reference will be looked up when it is loaded. If the relationship has a link it will use the "link" otherwise it defaults to "id".
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { data: [{ type: 'comment', id: 1 }] } } } }); let commentsRef = post.hasMany('comments'); // get the identifier of the reference if (commentsRef.remoteType() === "ids") { let ids = commentsRef.ids(); } else if (commentsRef.remoteType() === "link") { let link = commentsRef.link(); }
Defined in addon/-private/system/references/has-many.js:319
value()
sycronously returns the current value of the has-many relationship. Unlike record.get('relationshipName')
, calling value()
on a reference does not trigger a fetch if the async relationship is not yet loaded. If the relationship is not loaded it will always return null
.
Example
export default DS.Model.extend({ comments: DS.hasMany({ async: true }) });
let post = store.push({ data: { type: 'post', id: 1, relationships: { comments: { data: [{ type: 'comment', id: 1 }] } } } }); let commentsRef = post.hasMany('comments'); post.get('comments').then(function(comments) { commentsRef.value() === comments })
© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/ember-data/2.14/classes/DS.HasManyReference/methods