Page Contents

PersistedModel has a large set of methods for creating, updating, and deleting data.

Model data is also called a model instance; in database terminology, conceptually a model corresponds to a table, and a model instance corresponds to a row or record in the table.

Creating data (model instances)

Use the following PersistedModel methods to add data, that is to insert or create instances:

  • create - creates a new model instance (record).
  • upsert - checks if the instance (record) exists, based on the designated ID property, which must have a unique value; if the instance already exists, the method updates that instance. Otherwise, it inserts a new instance.
  • findOrCreate - Find one instance matching the filter object provided as the first parameter. If found, returns the object. If not found, creates a new instance (record).

  • save - Save model instance. If the instance doesn’t have an ID, then calls create instead. Triggers: validate, save, update, or create.

Updating data (model instances)

Static method (called on the Model object):

Instance methods (called on a single model instance):

Performing bulk updates

Describe why you would perform bulk updates.  Used with sync, for example.

Deleting data

Static methods (called on the Model object):