Extends
- Backbone.Model
Members
(static) idAttribute
Standard Backbone idAttribute property, automatically set to the ID key of the GraphQL type.
urlRoot
The Backbone urlRoot property is not used by PXDB_MODEL models. It is provided here as a reference to the tenant query URL, solely to prevent calls to the model's url method from signalling an error.
Methods
(static) isNew()
Overridden Backbone isNew() method. This detects when a model is newly created, versus one that is persisted. It relies on the sync() semantics.
(static) sync()
This is the overriden sync method, which calls pxdb.backbone_sync() to perform GraphQL queries and mutations. It should not be called directly.
expression()
Returns the filter expression used to retrieve this model. For a model, this is always a simple ID lookup; filter expressions cannot be set on models.
selection(newselect) → {array}
Sets and/or returns the 'selection',
that is, what fields are queried and returned on
the model. This is checked against the schema, so
only valid attributes can be queried.
Additionally, the ID attribute is required.
The selection must be formatted as follows: an array of either strings, for scalar fields, or objects, for subselection of linked types: the key is the linked type name, value is an array of fields to select on that type.
For instance, consider a type "Person" that has fields "personid", "firstname", "lastname", and a linked type "EmailAddress" with fields "personid" and "email" on it; to select the personid, firstname, lastname, and EmailAddress_collection on the Person type, with the email on the EmailAddress linked type, the selection would be formatted like so:
['personid', 'firstname', 'lastname', {EmailAddress_collection: ['email']}].
NB: This method sets the selection on a specific model object; the model's collection may have a different selection set, and is unaffected by calling selection() on the model object.
Parameters:
Name | Type | Description |
---|---|---|
newselect |
array | New selection to assign. If not provided, the existing selection is returned. |
Returns:
Selection currently set on this model.
- Type
- array
url()
Returns the PXDB_MODEL#urlRoot.
For GraphQL objects, all models have the same query
root, so this method is not meaningful.
validate()
This validation method automatically prevents invalid mutations. It disallows setting attributes that are not defind for the GraphQL schema type, setting attributes to the wrong underlying scalar type, and setting attributes that are only defined for the query type, but not the input type.
Standard Backbone validation semantics, as described at http://backbonejs.org/#Model-validate.