DS.ManyArray

DS.ManyArray Class

Extends: Ember.Object

Uses: Ember.MutableArray

Uses: Ember.Evented

Defined in: addon/-private/system/many-array.js:12

Module: ember-data

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.

Inverses

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

app/models/post.js
import DS from 'ember-data';

export default DS.Model.extend({
  comments: DS.hasMany('comment')
});
app/models/comment.js
import DS from 'ember-data';

export default DS.Model.extend({
  post: DS.belongsTo('post')
});

If you created a new instance of App.Post and added a App.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 the relationship's owner.

createRecord (hash) DS.Modelprivate

Defined in addon/-private/system/many-array.js:291

Create a child record within the owner

Parameters:

hash Object

Returns:

DS.Model
record

loadedRecordprivate

Defined in addon/-private/system/many-array.js:224

loadingRecordsCount (count) private

Defined in addon/-private/system/many-array.js:215

Parameters:

count Number

reloadpublic

Defined in addon/-private/system/many-array.js:236

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

var user = store.peekRecord('user', 1)
user.login().then(function() {
  user.get('permissions').then(function(permissions) {
    return permissions.reload();
  });
});

saveDS.PromiseArray

Defined in addon/-private/system/many-array.js:263

Saves all of the records in the ManyArray.

Example

store.findRecord('inbox', 1).then(function(inbox) {
  inbox.get('messages').then(function(messages) {
    messages.forEach(function(message) {
      message.set('isRead', true);
    });
    messages.save()
  });
});

Returns:

DS.PromiseArray
promise

isLoadedBoolean

Defined in addon/-private/system/many-array.js:59

The loading state of this array

isPolymorphicBooleanprivate

Defined in addon/-private/system/many-array.js:116

true if the relationship is polymorphic, false otherwise.

metaObjectpublic

Defined in addon/-private/system/many-array.js:76

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 metadata via the meta property:

post.get('comments').then(function(comments) {
  var meta = comments.get('meta');

// meta.page => 1
// meta.total => 5
});

promiseEmber.RSVP.Promiseprivate

Defined in addon/-private/system/many-array.js:67

Used for async hasMany arrays to keep track of when they will resolve.

relationshipManyRelationshipprivate

Defined in addon/-private/system/many-array.js:124

The relationship which manages this array.

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/data/classes/DS.ManyArray.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部