ModelCollectionProperty

model. ModelCollectionProperty

A ModelCollectionProperty instance is a ModelCollection that is a property of a model instance. ModelCollectionProperties can be operated on independently of the Model that owns them.

Constructor

new ModelCollectionProperty(parentModel, modelDefinition, propName, values, api)

Source:

Creates a new ModelCollectionProperty object. This is a subclass of ModelCollection, which adds logic for adding and removing elements to the collection and saving the changes to the API.

If the value is true or undefined is specified instead of an array of data values, this indicates that the collection contains (or may contain) data that has not yet been loaded from the API.

Parameters:
Name Type Description
parentModel Model

The Model of the parent of this ModelCollectionProperty

modelDefinition ModelDefinition

The ModelDefinition that this ModelCollection property is for

propName String

The name of this property on the parent model

values Array.<Model> | boolean

Initial values that should be added to the collection property

api Api

The class to use for API calls

Methods

(static) create(parentModel, modelDefinition, values) → {ModelCollectionProperty}

Source:

See ModelCollectionProperty.constructor.

Parameters:
Name Type Description
parentModel Model
modelDefinition ModelDefinition
values Array.<Model>
Returns:
Type
ModelCollectionProperty

add(value) → {ModelCollectionProperty}

Source:

Calls the add method on the parent ModelCollection class, and then performs checks to keep track of what, if any, changes that have been made to the collection.

Parameters:
Name Type Description
value Model

Model instance to add to the collection.

Returns:

Returns itself for chaining purposes.

Type
ModelCollectionProperty

isDirty(includeValuesopt) → {boolean}

Source:

Checks if the collection property has been modified.

Parameters:
Name Type Attributes Default Description
includeValues boolean <optional>
true

If true, also checks if any models in the collection has been edited by checking the dirty flag on each model.

Returns:

true if any elements have been added to or removed from the collection

Type
boolean

remove(value) → {ModelCollectionProperty}

Source:

If the collection contains an object with the same id as the value parameter, that object is removed from the collection. Checks are then performed to keep track of what, if any, changes that have been made to the collection.

Parameters:
Name Type Description
value Model

Model instance to remove from the collection.

Returns:

Returns itself for chaining purposes.

Type
ModelCollectionProperty

resetDirtyState()

Source:

Sets dirty=false and resets the added and removed sets used for dirty state tracking.

save() → {Promise}

Source:

If any changes have been made to the collection, these changes will be submitted to the API. The returned promise will resolve successfully when the changes have been saved to the API, and will be rejected if either the changes weren't saved or if there were no changes to save.

Returns:

A Promise

Type
Promise

updateDirty() → {boolean}

Source:

Checks whether any changes have been made to the collection, and updates the dirty flag accordingly.

Returns:

True if the collection has changed, false otherwise.

Type
boolean