new Model(Attributes, Options)
To create a new model include `isNew` in the options:
Parameters:
Name | Type | Description |
---|---|---|
Attributes |
Object | |
Options |
Object |
- Source:
Extends
- XM.ModelMixin
- Backbone.RelationalModel
Methods
-
_fetchHelper()
-
Prepare fetch. TODO sync() alone should handle all of this stuff. fetch() is not a Backbone customization point by design.
- Source:
-
bindEvents()
-
A function that binds events to functions. It can and should only be called once by initialize. Any attempt to call it a second time will throw an error.
- Source:
-
build()
-
Overload: assume that anything calling this function is doing so because it is building a model for a relation. In that case set the `isFetching` option is true which will set it in a `BUSY_FETCHING` state when it is created.
- Source:
-
destroy() → {Object|Boolean}
-
Reimplemented to handle state change and parent child relationships. Calling `destroy` on a parent will cause the model to commit to the server immediately. Calling destroy on a child relation will simply mark it for deletion on the next save of the parent.
- Source:
Returns:
- Type
- Object | Boolean
-
fetch(Options) → {Object}
-
Parameters:
Name Type Description Options
Object - Source:
Returns:
Request- Type
- Object
-
fetchId() → {Object}
-
Set the id on this record an id from the server. Including the `cascade` option will call ids to be fetched recursively for `HasMany` relations.
- Source:
Returns:
Request- Type
- Object
-
fetchRelated(key, options, update) → {Array}
-
Retrieve related objects.
Parameters:
Name Type Description key
String The relation key to fetch models for. options
Object Options for 'Backbone.Model.fetch' and 'Backbone.sync'. update
Boolean Whether to force a fetch from the server (updating existing models). - Source:
Returns:
An array of request objects.- Type
- Array
-
findOrCreate()
-
Overload: Need to handle status here
- Source:
-
getClass() → {XM.Model}
-
Returns the current model prototype class.
- Source:
Returns:
- Type
- XM.Model
-
getParent(Get) → {XM.Model}
-
Return the parent model if one exists. If the `getRoot` parameter is passed, it will return the top level parent of the model hierarchy.
Parameters:
Name Type Description Get
Boolean Root - Source:
Returns:
- Type
- XM.Model
-
initialize()
-
Called when model is instantiated.
- Source:
-
isReadOnly(attribute) → {Boolean}
-
Return whether the model is in a read-only state. If an attribute name is passed, returns whether that attribute is read-only. It is also capable of checking the read only status of child objects via a search path string.
// Inquire on the whole model var readOnly = this.isReadOnly(); // Inquire on a single attribute var readOnly = this.isReadOnly("name"); // Inquire using a search path var readOnly = this.isReadOnly("contact.firstName");
Parameters:
Name Type Description attribute
String - Source:
Returns:
- Type
- Boolean
-
obtainLock()
-
Attempt to obtain lock.
- Source:
Fires:
- lock:obtain
-
parse(Response)
-
Recursively checks the object against the schema and converts date strings to date objects.
Parameters:
Name Type Description Response
Object - Source:
-
releaseLock()
-
Release lock.
- Source:
Fires:
- lock:release
-
renewLock()
-
Attempt to renew lock.
- Source:
Fires:
- lock:renew
-
revert()
-
Revert a model back to its original state the last time it was fetched.
- Source:
-
revertStatus()
-
Revert the model to the previous status. Useful for reseting status after a failed validation. param {Boolean} - cascade
- Source:
-
save()
-
Reimplemented.
- Source:
-
set(Key, Value, Options)
-
Overload: Don't allow setting when model is in error or destroyed status, or updating a `READY_CLEAN` record without update privileges.
Parameters:
Name Type Description Key
String | Object Value
String | Object or Options Options
Objecw - Source:
-
setStatus(Status)
-
Set the status on the model. Triggers `statusChange` event. Option set to `cascade` will propagate status recursively to all HasMany children.
Parameters:
Name Type Description Status
Number - Source:
-
setValue()
-
Set a value(s) on attributes if key(s) is/are in schema, otherwise set on `meta`. If `meta` is null then behaves the same as `setIfExists`. Supports path strings.
- Source:
-
toJSON()
-
Overload: Delete objects marked as destroyed from arrays and convert dates to strings. Add support for 'includeNested' option that will output JSON with nested toOne objects when specified.
- Source:
-
validate(Attributes, Options)
-
Default validation checks `attributes` for:
* Data type integrity.
* Required fields.
Returns `undefined` if the validation succeeded, or some value, usually an error message, if it fails.
Parameters:
Name Type Description Attributes
Object Options
Object - Source: