getRelatedCollection

getRelatedCollection(options) ⇒ Promise

Get Related Model Collection. By default, this method returns a cached in memory instance of the collection. You can also fetch the first and subsequent collection sets.

Kind: global function
Returns: Promise - A promise that resolves to a related Backbone.Collection
Since: v0.0.1

Param Type Description
options
options.fetch Boolean True to fetch the first set of the collection.
options.fetchNextSet Boolean True to fetch the next set of the collection. Calling this repeatedly will continue to return the next subsequent part of the collection.
options.link String the link name of the related model you would like to get data from. Link names will be lower snake_case with a few exceptions: - “Revenue Line Items” -> revenuelineitems - “Data Privacy” -> dataprivacy - “Quotes (Bill To)” -> (module: accounts) quotes, (module: others) billing_quotes - “Quotes (Ship To)” -> quotes_shipto

Example

// totalMeetings = 12, maxSize = 5;
 // with meetings not cached (never fetched)
 getRelatedCollection({ link: 'meetings', fetchNextSet: true }); // -> get collection with first 5 records
 getRelatedCollection({ link: 'meetings', fetchNextSet: true }); // -> get collection with next 5 records
 getRelatedCollection({ link: 'meetings', fetchNextSet: true }); // -> get collection with remaining 2 records
 getRelatedCollection({ link: 'meetings', fetchNextSet: true }); // -> get collection with 0 records
 // To reset to the original collection see:
 [.resetPagination()](https://apidocs.sugarcrm.com/Sidecar/Data_BeanCollection.html#resetPagination)

 // never fetched
 getRelatedCollection({ link: 'meetings' }); // -> { length: 0, models: Array(0), ... }

 // fetch initial data
 getRelatedCollection({ link: 'meetings', fetch: true }); // -> { length: 5, models: Array(5), ... }

 // return cached data
 getRelatedCollection({ link: 'meetings' }); // -> { length: 5, models: Array(5), ... }

 // defined
 // Returns a promise that either
 //  - resolves to A Backbone.Collection { length: 20, models: Array(20), ... }
 //  - rejects if
         - link does not exist for the module
         - an error fetching from server

 // Example showing how to update a record from a related collection
 const meetings = await getRelatedCollection({ link: 'meetings' });
 const meeting = meetings.models.find(meeting => meeting.id === 'testMeetingId');
 await updateRecord({ record: meeting, updatedAttributes: { name: 'updated name' }});
 // done!