hasMany (name) HasManyReference
Get the reference for the specified hasMany relationship.
Example
// models/blog.js export default DS.Model.extend({ comments: DS.hasMany({ async: true }) }); var blog = store.push({ type: 'blog', id: 1, relationships: { comments: { data: [ { type: 'comment', id: 1 }, { type: 'comment', id: 2 } ] } } }); var commentsRef = blog.hasMany('comments'); // check if the comments are loaded already var isLoaded = commentsRef.value() !== null; // get the records of the reference (null if not yet available) var comments = commentsRef.value(); // get the identifier of the reference if (commentsRef.remoteType() === "ids") { var ids = commentsRef.ids(); } else if (commentsRef.remoteType() === "link") { var link = commentsRef.link(); } // load comments (via store.findMany or store.findHasMany) commentsRef.load().then(...) // or trigger a reload commentsRef.reload().then(...) // provide data for reference commentsRef.push([{ type: 'comment', id: 1 }, { type: 'comment', id: 2 }]).then(function(comments) { commentsRef.value() === comments; });
Parameters:
-
name
String
- of the relationship
Returns:
-
HasManyReference
- reference for this relationship
Please login to continue.