Class HasManyReference
publicA HasManyReference
is a low-level API that allows users and addon
authors to perform meta-operations on a has-many relationship.
ids Array public
Defined in ../packages/model/src/-private/references/has-many.ts:209
- returns
- Array
The ids in this has-many relationship
ids()
returns an array of the record IDs in this relationship.
Example
```js {data-filename=app/models/post.js} import Model, { hasMany } from '@ember-data/model';
export default class PostModel extends Model {
link String public
Defined in ../packages/model/src/-private/references/has-many.ts:248
- returns
- String
The link Ember Data will use to fetch or reload this belongs-to relationship.
The link Ember Data will use to fetch or reload this belongs-to relationship. By default it uses only the "related" resource linkage.
Example
// models/blog.js
import Model, { belongsTo } from '@ember-data/model';
export default Model.extend({
user: belongsTo('user', { async: true, inverse: null })
});
let blog = store.push({
data: {
type: 'blog',
id: 1,
relationships: {
user: {
links: {
related: '/articles/1/author'
}
}
}
}
});
let userRef = blog.belongsTo('user');
// get the identifier of the reference
if (userRef.remoteType() === "link") {
let link = userRef.link();
}
links public
Defined in ../packages/model/src/-private/references/has-many.ts:298
- returns
any links that have been received for this relationship
load (options) Promise public
Defined in ../packages/model/src/-private/references/has-many.ts:544
- options
- Object
the options to pass in.
- returns
- Promise
a promise that resolves with the ManyArray in this has-many relationship.
Loads the relationship if it is not already loaded. If the relationship is already loaded this method does not trigger a new load. This causes a request to the specified relationship link or reloads all items currently in the relationship.
Example
```js {data-filename=app/models/post.js} import Model, { hasMany } from '@ember-data/model';
export default class PostModel extends Model {
meta Object public
Defined in ../packages/model/src/-private/references/has-many.ts:311
- returns
- Object
The meta information for the belongs-to relationship.
The meta data for the has-many relationship.
Example
// models/blog.js
import Model, { hasMany } from '@ember-data/model';
export default Model.extend({
users: hasMany('user', { async: true, inverse: null })
});
let blog = store.push({
data: {
type: 'blog',
id: 1,
relationships: {
users: {
links: {
related: {
href: '/articles/1/authors'
},
},
meta: {
lastUpdated: 1458014400000
}
}
}
}
});
let usersRef = blog.hasMany('user');
usersRef.meta() // { lastUpdated: 1458014400000 }
push (objectOrPromise) ManyArray public
Defined in ../packages/model/src/-private/references/has-many.ts:360
- objectOrPromise
- Array|Promise
a promise that resolves to a JSONAPI document object describing the new value of this relationship.
- returns
- ManyArray
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
```js {data-filename=app/models/post.js} import Model, { hasMany } from '@ember-data/model';
export default class PostModel extends Model {
reload (options) Promise public
Defined in ../packages/model/src/-private/references/has-many.ts:619
- options
- Object
the options to pass in.
- returns
- Promise
a promise that resolves with the ManyArray in this has-many relationship.
Reloads this has-many relationship. This causes a request to the specified relationship link or reloads all items currently in the relationship.
Example
```js {data-filename=app/models/post.js} import Model, { hasMany } from '@ember-data/model';
export default class PostModel extends Model {
remoteType String public
Defined in ../packages/model/src/-private/references/has-many.ts:158
- returns
- String
The name of the remote type. This should either be
link
orids
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
```js {data-filename=app/models/post.js} import Model, { hasMany } from '@ember-data/model';
export default class PostModel extends Model {
value ManyArray public
Defined in ../packages/model/src/-private/references/has-many.ts:486
- returns
- ManyArray
value()
synchronously returns the current value of the has-many
relationship. Unlike record.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
```js {data-filename=app/models/post.js} import Model, { hasMany } from '@ember-data/model';
export default class PostModel extends Model {