Skip to content

Documentation / @ember-data/model / index / ManyArray

Interface: ManyArray<T>

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:50

A ManyArray is a MutableArray that represents the contents of a has-many relationship.

The ManyArray is instantiated lazily the first time the relationship is requested.

This class is not intended to be directly instantiated by consuming applications.

Inverses

Often, the relationships in Ember Data applications will have an inverse. For example, imagine the following models are defined:

app/models/post.js
js
import Model, { hasMany } from '@ember-data/model';

export default class PostModel extends Model {
@hasMany('comment') comments;
}
app/models/comment.js
js
import { Model, belongsTo } from '@warp-drive/legacy/model';

export default class CommentModel extends Model {
@belongsTo('post') post;
}

If you created a new instance of Post and added a Comment record to its comments has-many relationship, you would expect the comment's post property to be set to the post that contained the has-many.

We call the record to which a relationship belongs-to the relationship's owner.

Extends

  • ReactiveResourceArray<T>

Type Parameters

T

T = unknown

Indexable

ts
[key: number]: T

Methods

createRecord()

ts
createRecord(hash): T;

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:89

Create a child record and associated it to the collection

Parameters

hash

CreateRecordProperties<T>

Returns

T


reload()

ts
reload(options?): Promise<LegacyManyArray<T>>;

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:83

Reloads all of the records in the manyArray. If the manyArray holds a relationship that was originally fetched using a links url WarpDrive will revisit the original links url to repopulate the relationship.

If the ManyArray holds the result of a store.query() reload will re-run the original query.

Example

javascript
let user = store.peekRecord('user', '1')
await login(user);

let permissions = await user.permissions;
await permissions.reload();

Parameters

options?

BaseFinderOptions

Returns

Promise<LegacyManyArray<T>>

Properties

isLoaded

ts
isLoaded: boolean;

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:61

The loading state of this array


ts
links: 
  | null
  | Links
  | PaginationLinks;

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:52


meta

ts
meta: 
  | null
  | ObjectValue;

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:51


save()

ts
save: () => Promise<LegacyManyArray<T>>;

Defined in: warp-drive-packages/core/declarations/store/-private/record-arrays/legacy-many-array.d.ts:109

Saves all of the records in the ManyArray.

Note: this API can only be used in legacy mode with a configured Adapter.

Example

js
const { content: { data: inbox } } = await store.request(findRecord({ type: 'inbox', id: '1' }));

let messages = await inbox.messages;
messages.forEach((message) => {
message.isRead = true;
});
messages.save();

Returns

Promise<LegacyManyArray<T>>

Released under the MIT License.