new Data/MixedBeanCollection()
Mixed collection class.
Supports wrapping multiple related collections by link to allow aggregated interactions across multiple bean relationships. Does not support direct fetch at this time except in search mode.
Filtering and searching
The collection's Data/BeanCollection#fetch method supports filter and
search options. For example, to search across accounts, opportunities, and
contacts for favorite records that have the string "Acme" in their
searchable fields:
const DataManager = require('data/data-manager');
var records = SUGAR.App.data.getMixedBeanCollection();
records.fetch({
favorites: true,
query: 'Acme',
module_list: 'Accounts,Opportunities,Contacts'
});
Extends
Members
-
<readonly> favorites :boolean
-
Flag indicating if a collection contains current user's favorite items.
Type:
- boolean
- Inherited From:
-
fields :Array
-
Field names.
A list of fields that are populated on collection members. This property is used to build the
fieldsURL parameter when fetching beans.Type:
- Array
- Inherited From:
-
filterDef :Array
-
Filter definition to filter the collection by.
Type:
- Array
- Inherited From:
-
link :Object
-
Reference to a relationship.
Type:
- Object
- Inherited From:
- Overrides:
-
<readonly> model :Data/Bean
-
The default model of a bean collection is a Data/Bean.
Type:
- Inherited From:
-
<readonly> modelList :string
-
List of modules searched.
Type:
- string
-
<readonly> module :string
-
The module name.
Type:
- string
- Inherited From:
-
<readonly> myItems :boolean
-
Flag indicating if a collection contains items assigned to the current user.
Type:
- boolean
- Inherited From:
-
<readonly> offset :number
-
Current collection offset for pagination.
Type:
- number
- Inherited From:
-
<readonly> query :string
-
Search query.
Type:
- string
- Inherited From:
-
<readonly> total :number
-
Readonly property for the total records in server.
Use Data/BeanCollection#fetchTotal to get the current total.
Type:
- number
- Inherited From:
Methods
-
<protected> _decrementTotal()
-
Decrements the collection total.
- Inherited From:
-
abortFetchRequest()
-
Aborts the currently active fetch request.
- Inherited From:
-
add(models, options)
-
Keeps track of the added models.
Parameters:
Name Type Description modelsObject | Array.<Object> | Data/Bean | Array.<Data/Bean> The models to add.
optionsObject A hash of options.
- Inherited From:
Returns:
The added models.
-
clone()
-
Clones the collection including the Data/BeanCollection#link and all the persistent options.
- Inherited From:
Returns:
The new collection with an identical list of models as this one.
- Type
- Data/BeanCollection
-
constructor(models [, options])
-
Prepares related bean collections and attach collection plugins.
Parameters:
Name Type Argument Description modelsArray.<Object> | Array.<Data/Bean> Initial array of models.
optionsObject <optional>
A hash of options.
Properties
Name Type Argument Description linkObject <optional>
A link specification.
- Inherited From:
-
dispose()
-
Disposes this collection.
- Inherited From:
-
fetch( [options])
-
Fetches records.
This method performs global search across multiple modules.
Parameters:
Name Type Argument Description optionsObject <optional>
Fetch options.
Properties
Name Type Argument Description module_liststring <optional>
Comma-delimited list of modules to search across. The default is a list of all displayable modules.
- Overrides:
Returns:
The created fetch request.
- Type
- SUGAR.HttpRequest
-
fetchTotal( [options])
-
Fetches the total amount of records on the bean collection, and sets it on the Data/BeanCollection#total property.
Returns the total amount of filtered records if a
filterDefproperty is set on the collection.Parameters:
Name Type Argument Description optionsObject <optional>
Fetch total options.
Properties
Name Type Argument Description successfunction <optional>
Success callback.
completefunction <optional>
Complete callback.
errorfunction <optional>
Error callback.
- Inherited From:
Returns:
Result of SUGAR.Api#call, or
undefinedif Data/BeanCollection#total is notnull.- Type
- SUGAR.HttpRequest | undefined
-
getDelta()
-
Gets changes made on the linked collections.
- Overrides:
Returns:
The object representing the changes made on the linked collections since the last sync.
- Type
- Object
-
getFetchRequest()
-
Gets the currently active fetch request.
- Inherited From:
Returns:
The currently active http fetch request.
- Type
- SUGAR.HttpRequest
-
getModelIndex(model)
-
Returns the index of the model in this collection.
Parameters:
Name Type Description modelObject Current model.
- Inherited From:
Returns:
The index of the passed
modelin this array.- Type
- number
-
getNext(current, callback)
-
Returns the next model in a collection, paginating if needed.
Parameters:
Name Type Description currentObject Current model or id of a model.
callbackObject Callback for success call.
- Inherited From:
-
getOption( [key])
-
Gets one or all persistent fetch options.
Parameters:
Name Type Argument Description keystring | Object <optional>
The name of the option to retrieve, or nothing to retrieve all options.
- Inherited From:
Returns:
A specific option, or the list of options.
- Type
- *
-
getPageNumber( [options])
-
Gets the current page of collection being displayed depending on the offset.
Parameters:
Name Type Argument Description optionsObject <optional>
Fetch options used when paginating.
Properties
Name Type Argument Default Description limitnumber <optional>
App.config.maxQueryResult The size of each page.
- Inherited From:
Returns:
The current page number.
- Type
- number
-
getPrev(current, callback)
-
Finds the previous model in a collection and calls a function on it.
Parameters:
Name Type Description currentObject Current model or id of a model.
callbackfunction Callback for success call.
- Inherited From:
-
groupByModule()
-
Groups models by module name.
Returns:
Sets of models. Key is module name, value is array of models.
- Type
- Object
-
hasAtLeast(amount [, options])
-
A convenience method that checks to see if there are at least the amount of records passed in
amount. Also passes to a provided success callback the length of records up toamount, and if there are more records to be fetched (hasMore).Fetches the partial amount of filtered records if a
filterDefproperty is set on the collection.Parameters:
Name Type Argument Description amountnumber The number of records to check if there are a minimum of.
optionsObject <optional>
Fetch partial total options.
Properties
Name Type Argument Description filterDefObject <optional>
Filter definition to be applied.
successfunction <optional>
Success callback.
completefunction <optional>
Complete callback.
errorfunction <optional>
Error callback.
- Inherited From:
Returns:
Result of SUGAR.Api#call.
- Type
- SUGAR.HttpRequest
-
hasDelta()
-
Checks if at least one of the linked collections has a delta.
- Overrides:
Returns:
trueif at least 1 linked collection has a delta.- Type
- boolean
-
hasNextModel(current)
-
Checks whether is there next model in collection.
Parameters:
Name Type Description currentObject Current model or id of a model.
- Inherited From:
Returns:
trueif has next model,falseotherwise.- Type
- boolean
-
hasPreviousModel(current)
-
Checks whether is there previous model in this collection.
Parameters:
Name Type Description currentObject Current model or id of a model.
- Inherited From:
Returns:
trueif has previous model,falseotherwise.- Type
- boolean
-
initialize(models [, options])
-
Creates a bean collection for each one of the links passed in the options. The mixed bean collection will keep those collection in sync with the mixed bean collection.
Parameters:
Name Type Argument Description modelsArray The initial models of the mixed bean collection.
optionsObject <optional>
A hash of options.
Properties
Name Type Argument Description linksArray <optional>
The links related to the mixed bean collection. A link is a collection of a particular module linked to a Bean. It represents a 1-to-many or many-to-many relationship. If this argument is provided, the mixed bean collection will handle synchronization between its records and the ones in its link collections. This allows a bean to have a mixed bean collection as part of its attributes to handle modification on its 1-to-many and many-to-many relationships.
parentBeanData/Bean <optional>
The parent bean. It is required in the case where the MixedBeanCollection is used for a collection field.
- Overrides:
-
paginate( [options])
-
Paginates the collection. In the use case of a collection field, we pass
collectionFieldoption in order to hit the collection API.Parameters:
Name Type Argument Description optionsObject <optional>
A hash of options.
Properties
Name Type Argument Description storedFilterArray.<string> <optional>
An array of existing filters to be applied.
viewstring <optional>
If you are paginating a collection field, passing the
viewoption will make sure we read the field definition specified in the view defs. It is especially important in order to use the sameorder_byvalue that was used for the first fetch of the collection.- Overrides:
Returns:
The created fetch request.
- Type
- SUGAR.HttpRequest
-
remove(models [, options])
-
Removes models from the matching linked collections.
Parameters:
Name Type Argument Description modelsArray.<Data/Bean> | Array.<Object> The beans to be removed from the collection.
optionsObject <optional>
A hash of options.
- Overrides:
Returns:
The beans removed from the collection.
- Type
- Array.<Data/Bean>
-
reset(models [, options])
-
Resets all linked collections.
Parameters:
Name Type Argument Description modelsArray.<Data/Bean> | Array.<Object> The beans to reset the collection with.
optionsObject <optional>
A hash of options.
- Overrides:
Returns:
The beans set to the collection.
- Type
- Array.<Data/Bean>
-
resetDelta()
-
Resets the delta object on each linked collection.
- Overrides:
-
resetPagination()
-
In a use case of a collection field, we set the
offsetandnext_offsetto an empty object. In other use cases, we call the parent.- Overrides:
-
set(models [, options])
-
Adds models to the matching linked collections.
Parameters:
Name Type Argument Description modelsArray.<Data/Bean> | Array.<Object> The beans to be added to the collection.
optionsObject <optional>
A hash of options.
Returns:
The beans added to the collection.
- Type
- Array.<Data/Bean>
-
setOption(key [, val])
-
Sets the default fetch options (one or many) on the model.
Parameters:
Name Type Argument Description keystring | Object The name of the attribute, or a hash of attributes.
val* <optional>
The default value for the
keyargument.- Inherited From:
Returns:
This instance.
- Type
- Data/BeanCollection
-
toString()
-
Returns string representation of this collection.
The format is:
mcoll:[length]- Overrides:
Returns:
String representation of this collection.
- Type
- string
-
unsetOption( [key])
-
Unsets a default fetch option (or all).
Parameters:
Name Type Argument Description keystring | Object <optional>
The name of the option to unset, or nothing to unset all options.
- Inherited From:
Returns:
This instance.
- Type
- Data/BeanCollection