home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
4.12
  • Packages
    • @ember-data/adapter
    • @ember-data/adapter/error
    • @ember-data/adapter/json-api
    • @ember-data/adapter/rest
    • @ember-data/canary-features
    • @ember-data/debug
    • @ember-data/deprecations
    • @ember-data/experimental-preview-types
    • @ember-data/graph
    • @ember-data/json-api
    • @ember-data/legacy-compat
    • @ember-data/model
    • @ember-data/request
    • @ember-data/request/fetch
    • @ember-data/serializer
    • @ember-data/serializer/json
    • @ember-data/serializer/json-api
    • @ember-data/serializer/rest
    • @ember-data/store
    • @ember-data/tracking
  • Classes
    • <Interface> Adapter
    • <Interface> Cache
    • <Interface> Handler
    • <Interface> Serializer
    • AbortError
    • Adapter
    • AdapterError
    • BelongsToReference
    • BooleanTransform
    • BuildURLMixin
    • Cache
    • CacheManager
    • CacheStoreWrapper
    • CanaryFeatureFlags
    • ConflictError
    • CurrentDeprecations
    • DateTransform
    • DebugLogging
    • EmbeddedRecordsMixin
    • Errors
    • Fetch
    • ForbiddenError
    • Future
    • HasManyReference
    • IdentifierCache
    • InvalidError
    • JSONAPIAdapter
    • JSONAPISerializer
    • JSONSerializer
    • ManyArray
    • Model
    • NotFoundError
    • NotificationManager
    • NumberTransform
    • PromiseArray
    • PromiseManyArray
    • PromiseObject
    • RESTAdapter
    • RESTSerializer
    • RecordArray
    • RecordReference
    • RequestManager
    • RequestStateService
    • SchemaService
    • Serializer
    • ServerError
    • Snapshot
    • SnapshotRecordArray
    • StableRecordIdentifier
    • Store
    • StringTransform
    • TimeoutError
    • Transform
    • UnauthorizedError

Class ManyArray public


Defined in: ../model/src/-private/many-array.ts:45
Module: @ember-data/store

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:

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

export default class PostModel extends Model {


Methods

createRecord (hash) : Model public

Module: @ember-data/store

Defined in ../packages/model/src/-private/many-array.ts:332

hash
Object
returns
Model

record

Create a child record within the owner

reload public

Module: @ember-data/store

Defined in ../packages/model/src/-private/many-array.ts:286

Reloads all of the records in the manyArray. If the manyArray holds a relationship that was originally fetched using a links url Ember Data 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

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

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

save : PromiseArray public

Module: @ember-data/store

Defined in ../packages/model/src/-private/many-array.ts:313

returns
PromiseArray

promise

Saves all of the records in the ManyArray.

Example

let inbox = await store.findRecord('inbox', '1');
let messages = await inbox.messages;
messages.forEach((message) => {
  message.isRead = true;
});
messages.save();

Properties

isLoaded public

Module: @ember-data/store

Defined in ../packages/model/src/-private/many-array.ts:90

The loading state of this array

links public

Module: @ember-data/store

Defined in ../packages/model/src/-private/many-array.ts:144

Retrieve the links for this relationship

meta public

Module: @ember-data/store

Defined in ../packages/model/src/-private/many-array.ts:106

Metadata associated with the request for async hasMany relationships.

Example

Given that the server returns the following JSON payload when fetching a hasMany relationship:

{
  "comments": [{
    "id": 1,
    "comment": "This is the first comment",
  }, {
// ...
  }],

  "meta": {
    "page": 1,
    "total": 5
  }
}

You can then access the meta data via the meta property:

let comments = await post.comments;
let meta = comments.meta;

// meta.page => 1
// meta.total => 5
On this page


Methods

  • createRecord
  • reload
  • save

Properties

  • isLoaded
  • links
  • meta
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.