Class: PXDB_MODEL

PXDB_MODEL()

A PXDB_MODEL class represents a single model of the corresponding GraphQL type. This is equivalent to a single database row.

There is no class named PXDB_MODEL; this is a 'metaclass', a form of class that will be generated for each of the schema types in the GraphQL schema. The classes will be stored on the classes property of the engine instance, with names specified as documented at pxdb.create_backbone_classes().

Except where specified, PXDB_MODEL classes work identically to standard Backbone Models.

In this documentation, wherever PXDB_MODEL is stated, replace with the actual class name for the object type.

Constructor

new PXDB_MODEL()

Source:

Extends

  • Backbone.Model

Members

(static) idAttribute

Standard Backbone idAttribute property, automatically set to the ID key of the GraphQL type.

Source:

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.

Source:

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.

Source:

(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.

Source:

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.

Source:

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.

Source:
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.

Source:

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.

Source: