DS.Snapshot#hasMany()

hasMany (keyName, options) (Array|undefined)

Defined in addon/-private/system/snapshot.js:238

Returns the current value of a hasMany relationship.

hasMany takes an optional hash of options as a second parameter, currently supported options are:

  • ids: set to true if you only want the IDs of the related records to be returned.

Example

// store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
postSnapshot.hasMany('comments'); // => [DS.Snapshot, DS.Snapshot]
postSnapshot.hasMany('comments', { ids: true }); // => ['2', '3']

// store.push('post', { id: 1, title: 'Hello World' });
postSnapshot.hasMany('comments'); // => undefined

Note: Relationships are loaded lazily and cached upon first access.

Parameters:

keyName String
options [Object]

Returns:

(Array|undefined)
An array of snapshots or IDs of a known relationship or an empty array if the relationship is known but unset. undefined will be returned if the contents of the relationship is unknown.
doc_EmberJs
2016-11-30 16:50:42
Comments
Leave a Comment

Please login to continue.