Model
Summary
A base class for API objects that provides abstract support for serialization and deserialization, matching by attributes, and ID-based equality.
Attributes
id
: {AttributeString} The resolved canonical ID of the model used in the
database and generally throughout the app. The id property is a custom
getter that resolves to the serverId first, and then the clientId.
clientId
: {AttributeString} An ID created at object construction and
persists throughout the lifetime of the object. This is extremely useful
for optimistically creating objects (like drafts and categories) and
having a constant reference to it. In all other cases, use the resolved
id
field.
serverId
: {AttributeServerId} The server ID of the model. In most cases,
except optimistic creation, this will also be the canonical id of the
object.
object
: {AttributeString} The model's type. This field is used by the JSON
deserializer to create an instance of the correct class when inflating the object.
accountId
: {AttributeString} The string Account Id this model belongs to.
Instance Methods
attributes()
Returns
Return Values |
---|
Returns an {Array} of {Attribute} objects defined on the Model's constructor |
toJSON([options])
Deflates the model to a plain JSON object. Only attributes defined on the model are included in the JSON.
Argument | Description |
---|---|
options | Optional An {Object} with additional options. To skip joined data attributes in the toJSON representation, pass the `joined:false` |
Returns
Return Values |
---|
Returns an {Object} with the JSON representation of the model. |
matches(criteria)
Evaluates the model against one or more {Matcher} objects.
Argument | Description |
---|---|
criteria | An {Array} of {Matcher}s to run on the model. |
Returns
Return Values |
---|
Returns true if the model matches the criteria. |