#
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.
#
fields :Array
Field names.
A list of fields that are populated on collection members.
This property is used to build the fields
URL parameter when
fetching beans.
#
filterDef :Array
Filter definition to filter the collection by.
#
link :Object
Reference to a relationship.
The default model of a bean collection is a Data/Bean.
#
(readonly) modelList :string
List of modules searched.
#
(readonly) module :string
#
(readonly) myItems :boolean
Flag indicating if a collection contains items assigned to the
current user.
#
(readonly) offset :number
Current collection offset for pagination.
#
(readonly) query :string
#
(readonly) total :number
Methods
#
(protected) _decrementTotal()
#
abortFetchRequest()
Aborts the currently active fetch request.
Keeps track of the added models.
Parameters:
Name |
Type |
Description |
models |
Object
|
Array.<Object>
|
Data/Bean
|
Array.<Data/Bean>
|
The models to add. |
options |
Object
|
A hash of options. |
Returns:
The new collection with an identical
list of models as this one.
-
Type
-
Data/BeanCollection
#
constructor(models, optionsopt)
Prepares related bean collections and attach collection plugins.
Parameters:
Name |
Type |
Attributes |
Description |
models |
Array.<Object>
|
Array.<Data/Bean>
|
|
Initial array of models. |
options |
Object
|
<optional>
|
A hash of options.
Properties
Name |
Type |
Attributes |
Description |
link |
Object
|
<optional>
|
A link specification. |
|
#
dispose()
Disposes this collection.
#
fetch(optionsopt) → {SUGAR.HttpRequest}
Fetches records.
This method performs global search across multiple modules.
Parameters:
Name |
Type |
Attributes |
Description |
options |
Object
|
<optional>
|
Fetch options.
Properties
Name |
Type |
Attributes |
Description |
module_list |
string
|
<optional>
|
Comma-delimited list of
modules to search across. The default is a list of all displayable
modules. |
|
Returns:
The created fetch request.
-
Type
-
SUGAR.HttpRequest
#
fetchTotal(optionsopt) → {SUGAR.HttpRequest|undefined}
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 filterDef
property is set on the collection.
Parameters:
Name |
Type |
Attributes |
Description |
options |
Object
|
<optional>
|
Fetch total options.
Properties
Name |
Type |
Attributes |
Description |
success |
function
|
<optional>
|
Success callback. |
complete |
function
|
<optional>
|
Complete callback. |
error |
function
|
<optional>
|
Error callback. |
|
Returns:
-
Type
-
SUGAR.HttpRequest
|
undefined
#
getDelta() → {Object}
Gets changes made on the linked collections.
Returns:
The object representing the changes made on the
linked collections since the last sync.
-
Type
-
Object
#
getFetchRequest() → {SUGAR.HttpRequest}
Gets the currently active fetch request.
Returns:
The currently active http fetch request.
-
Type
-
SUGAR.HttpRequest
#
getModelIndex(model) → {number}
Returns the index of the model in this collection.
Parameters:
Name |
Type |
Description |
model |
Object
|
Current model. |
Returns:
The index of the passed model
in this array.
-
Type
-
number
#
getNext(current, callback)
Returns the next model in a collection, paginating if needed.
Parameters:
Name |
Type |
Description |
current |
Object
|
Current model or id of a model. |
callback |
Object
|
Callback for success call. |
#
getOption(keyopt) → {*}
Gets one or all persistent fetch options.
Parameters:
Name |
Type |
Attributes |
Description |
key |
string
|
Object
|
<optional>
|
The name of the option to retrieve, or
nothing to retrieve all options. |
Returns:
A specific option, or the list of options.
-
Type
-
*
#
getPageNumber(optionsopt) → {number}
Gets the current page of collection being displayed depending on the
offset.
Parameters:
Name |
Type |
Attributes |
Description |
options |
Object
|
<optional>
|
Fetch options used when paginating.
Properties
Name |
Type |
Attributes |
Default |
Description |
limit |
number
|
<optional>
|
App.config.maxQueryResult
|
The size of
each page. |
|
#
getPrev(current, callback)
Finds the previous model in a collection and calls a function on it.
Parameters:
Name |
Type |
Description |
current |
Object
|
Current model or id of a model. |
callback |
function
|
Callback for success call. |
#
groupByModule() → {Object}
Groups models by module name.
Returns:
Sets of models. Key is module name, value is array of
models.
-
Type
-
Object
#
hasAtLeast(amount, optionsopt) → {SUGAR.HttpRequest}
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 to amount
, and if there
are more records to be fetched (hasMore
).
Fetches the partial amount of filtered records if a filterDef
property is set on the collection.
Parameters:
Name |
Type |
Attributes |
Description |
amount |
number
|
|
The number of records to check if there are a
minimum of. |
options |
Object
|
<optional>
|
Fetch partial total options.
Properties
Name |
Type |
Attributes |
Description |
filterDef |
Object
|
<optional>
|
Filter definition to be applied. |
success |
function
|
<optional>
|
Success callback. |
complete |
function
|
<optional>
|
Complete callback. |
error |
function
|
<optional>
|
Error callback. |
|
Returns:
Result of SUGAR.Api#call.
-
Type
-
SUGAR.HttpRequest
#
hasDelta() → {boolean}
Checks if at least one of the linked collections has a delta.
Returns:
true
if at least 1 linked collection has a delta.
-
Type
-
boolean
#
hasNextModel(current) → {boolean}
Checks whether is there next model in collection.
Parameters:
Name |
Type |
Description |
current |
Object
|
Current model or id of a model. |
Returns:
true
if has next model, false
otherwise.
-
Type
-
boolean
#
hasPreviousModel(current) → {boolean}
Checks whether is there previous model in this collection.
Parameters:
Name |
Type |
Description |
current |
Object
|
Current model or id of a model. |
Returns:
true
if has previous model, false
otherwise.
-
Type
-
boolean
#
initialize(models, optionsopt)
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 |
Attributes |
Description |
models |
Array
|
|
The initial models of the mixed bean collection. |
options |
Object
|
<optional>
|
A hash of options.
Properties
Name |
Type |
Attributes |
Description |
links |
Array
|
<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. |
parentBean |
Data/Bean
|
<optional>
|
The parent bean. It is required
in the case where the MixedBeanCollection is used for a collection
field. |
|
#
paginate(optionsopt) → {SUGAR.HttpRequest}
Paginates the collection. In the use case of a collection field, we
pass collectionField
option in order to hit the collection API.
Parameters:
Name |
Type |
Attributes |
Description |
options |
Object
|
<optional>
|
A hash of options.
Properties
Name |
Type |
Attributes |
Description |
storedFilter |
Array.<string>
|
<optional>
|
An array of existing filters to
be applied. |
view |
string
|
<optional>
|
If you are paginating a collection field,
passing the view option will make sure we read the field definition
specified in the view defs. It is especially important in order to use
the same order_by value that was used for the first fetch of the
collection. |
|
Returns:
The created fetch request.
-
Type
-
SUGAR.HttpRequest
#
remove(models, optionsopt) → {Array.<Data/Bean>}
Removes models from the matching linked collections.
Parameters:
Name |
Type |
Attributes |
Description |
models |
Array.<Data/Bean>
|
Array.<Object>
|
|
The beans to be removed from the
collection. |
options |
Object
|
<optional>
|
A hash of options. |
Returns:
The beans removed from the collection.
-
Type
-
Array.<Data/Bean>
#
reset(models, optionsopt) → {Array.<Data/Bean>}
Resets all linked collections.
Parameters:
Name |
Type |
Attributes |
Description |
models |
Array.<Data/Bean>
|
Array.<Object>
|
|
The beans to reset the
collection with. |
options |
Object
|
<optional>
|
A hash of options. |
Returns:
The beans set to the collection.
-
Type
-
Array.<Data/Bean>
#
resetDelta()
Resets the delta object on each linked collection.
In a use case of a collection field, we set the offset
and
next_offset
to an empty object. In other use cases, we call the parent.
#
set(models, optionsopt) → {Array.<Data/Bean>}
Adds models to the matching linked collections.
Parameters:
Name |
Type |
Attributes |
Description |
models |
Array.<Data/Bean>
|
Array.<Object>
|
|
The beans to be added to the
collection. |
options |
Object
|
<optional>
|
A hash of options. |
Returns:
The beans added to the collection.
-
Type
-
Array.<Data/Bean>
Sets the default fetch options (one or many) on the model.
Parameters:
Name |
Type |
Attributes |
Description |
key |
string
|
Object
|
|
The name of the attribute, or a hash of
attributes. |
val |
*
|
<optional>
|
The default value for the key argument. |
#
toString() → {string}
Returns string representation of this collection.
The format is:
mcoll:[length]
Returns:
String representation of this collection.
-
Type
-
string
Unsets a default fetch option (or all).
Parameters:
Name |
Type |
Attributes |
Description |
key |
string
|
Object
|
<optional>
|
The name of the option to unset, or
nothing to unset all options. |