API Docs for:

Class Parse.Object

Creates a new model with defined attributes.

You won't normally call this method directly. It is recommended that you use a subclass of Parse.Object instead, created by calling extend.

However, if you don't want to use a subclass, or aren't sure which subclass is appropriate, you can use this form:

    var object = new Parse.Object("ClassName");
That is basically equivalent to:
    var MyClass = Parse.Object.extend("ClassName");
    var object = new MyClass();

Parse.Object( className, attributes, options )
Parameters:
  • className <String>

    The class name for the object

  • attributes <Object>

    The initial set of data to store in the object.

  • options <Object>

    The options for this object instance.

add( attr, item )

Atomically add an object to the end of the array associated with a given key.

Parameters:
  • attr <String>

    The key.

  • item <Object>

    The item to add.

addUnique( attr, item )

Atomically add an object to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.

Parameters:
  • attr <String>

    The key.

  • item <Object>

    The object to add.

clear( )

Clears all attributes on a model

Parse.Object clone( )

Creates a new model with identical attributes to this one.


Returns: <Parse.Object>
Parse.Object createWithoutData( id )

Creates a reference to a subclass of Parse.Object with the given id. This does not exist on Parse.Object, only on subclasses.

A shortcut for:

 var Foo = Parse.Object.extend("Foo");
 var pointerToFoo = new Foo();
 pointerToFoo.id = "myObjectId";
Parameters:
  • id <String>

    The ID of the object to create a reference to.


Returns: <Parse.Object>

A Parse.Object reference.

Parse.Promise destroy( options )

Destroy this model on the server if it was already persisted. If wait: true is passed, waits for the server to respond before removal.

Parameters:
  • options <Object>

    A Backbone-style callback object. Valid options are:

    • success: A Backbone-style success callback
    • error: An Backbone-style error callback.
    • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
    • sessionToken: A valid session token, used for making a request on behalf of a specific user.

Returns: <Parse.Promise>

A promise that is fulfilled when the destroy completes.

Parse.Promise destroyAll( list, options )

Destroy the given list of models on the server if it was already persisted.

Unlike saveAll, if an error occurs while deleting an individual model, this method will continue trying to delete the rest of the models if possible, except in the case of a fatal error like a connection error.

In particular, the Parse.Error object returned in the case of error may be one of two types:

  • A Parse.Error.AGGREGATE_ERROR. This object's "errors" property is an array of other Parse.Error objects. Each error object in this array has an "object" property that references the object that could not be deleted (for instance, because that object could not be found).
  • A non-aggregate Parse.Error. This indicates a serious error that caused the delete operation to be aborted partway through (for instance, a connection failure in the middle of the delete).
  Parse.Object.destroyAll([object1, object2, ...], {
    success: function() {
      // All the objects were deleted.
    },
    error: function(error) {
      // An error occurred while deleting one or more of the objects.
      // If this is an aggregate error, then we can inspect each error
      // object individually to determine the reason why a particular
      // object was not deleted.
      if (error.code === Parse.Error.AGGREGATE_ERROR) {
        for (var i = 0; i < error.errors.length; i++) {
          console.log("Couldn't delete " + error.errors[i].object.id +
            "due to " + error.errors[i].message);
        }
      } else {
        console.log("Delete aborted because of " + error.message);
      }
    },
  });
Parameters:
  • list <Array>

    A list of Parse.Object.

  • options <Object>

    A Backbone-style callback object.


Returns: <Parse.Promise>

A promise that is fulfilled when the destroyAll completes.

Boolean dirty( attr )

Returns true if this object has been modified since its last save/refresh. If an attribute is specified, it returns true only if that particular attribute has been modified since the last save/refresh.

Parameters:
  • attr <String>

    An attribute name (optional).


Returns: <Boolean>
Array of string dirtyKeys( )

Returns an array of keys that have been modified since last save/refresh


Returns: <Array of string>
disableSingleInstance( )

Disable single instance objects, where any local objects with the same Id share the same attributes, and stay synchronized with each other. When disabled, you can have two instances of the same object in memory without them sharing attributes.

enableSingleInstance( )

Enable single instance objects, where any local objects with the same Id share the same attributes, and stay synchronized with each other. This is disabled by default in server environments, since it can lead to security issues.

Boolean equals( )

Determines whether this ParseObject is equal to another ParseObject


Returns: <Boolean>
escape( attr )

Gets the HTML-escaped value of an attribute.

Parameters:
  • attr <String>

    The string name of an attribute.

Boolean existed( )

Returns true if this object was created by the Parse server when the object might have already been there (e.g. in the case of a Facebook login)


Returns: <Boolean>
Class extend( className, protoProps, classProps )

Creates a new subclass of Parse.Object for the given Parse class name.

Every extension of a Parse class will inherit from the most recent previous extension of that class. When a Parse.Object is automatically created by parsing JSON, it will use the most recent extension of that class.

You should call either:

    var MyClass = Parse.Object.extend("MyClass", {
        Instance methods,
        initialize: function(attrs, options) {
            this.someInstanceProperty = [],
            Other instance properties
        }
    }, {
        Class properties
    });
or, for Backbone compatibility:
    var MyClass = Parse.Object.extend({
        className: "MyClass",
        Instance methods,
        initialize: function(attrs, options) {
            this.someInstanceProperty = [],
            Other instance properties
        }
    }, {
        Class properties
    });

Parameters:
  • className <String>

    The name of the Parse class backing this model.

  • protoProps <Object>

    Instance properties to add to instances of the class returned from this method.

  • classProps <Object>

    Class properties to add the class returned from this method.


Returns: <Class>

A new subclass of Parse.Object.

Parse.Promise fetch( options )

Fetch the model from the server. If the server's representation of the model differs from its current attributes, they will be overriden.

Parameters:
  • options <Object>

    A Backbone-style callback object. Valid options are:

    • success: A Backbone-style success callback.
    • error: An Backbone-style error callback.
    • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
    • sessionToken: A valid session token, used for making a request on behalf of a specific user.

Returns: <Parse.Promise>

A promise that is fulfilled when the fetch completes.

fetchAll( list, options )

Fetches the given list of Parse.Object. If any error is encountered, stops and calls the error handler.

  Parse.Object.fetchAll([object1, object2, ...], {
    success: function(list) {
      // All the objects were fetched.
    },
    error: function(error) {
      // An error occurred while fetching one of the objects.
    },
  });
Parameters:
  • list <Array>

    A list of Parse.Object.

  • options <Object>

    A Backbone-style callback object.

fetchAllIfNeeded( list, options )

Fetches the given list of Parse.Object if needed. If any error is encountered, stops and calls the error handler.

  Parse.Object.fetchAllIfNeeded([object1, ...], {
    success: function(list) {
      // Objects were fetched and updated.
    },
    error: function(error) {
      // An error occurred while fetching one of the objects.
    },
  });
Parameters:
  • list <Array>

    A list of Parse.Object.

  • options <Object>

    A Backbone-style callback object.

Parse.Object fromJSON( json )

Creates a new instance of a Parse Object from a JSON representation.

Parameters:
  • json <Object>

    The JSON map of the Object's data


Returns: <Parse.Object>

A Parse.Object reference

get( attr )

Gets the value of an attribute.

Parameters:
  • attr <String>

    The string name of an attribute.

Parse.ACL getACL( )

Returns the ACL for this object.


Returns: <Parse.ACL>

An instance of Parse.ACL.

Boolean has( attr )

Returns true if the attribute contains a value that is not null or undefined.

Parameters:
  • attr <String>

    The string name of the attribute.


Returns: <Boolean>
increment( attr, amount )

Atomically increments the value of the given attribute the next time the object is saved. If no amount is specified, 1 is used by default.

Parameters:
  • attr <String>

    The key.

  • amount <Number>

    The amount to increment by (optional).

Boolean isNew( )

Returns true if this object has never been saved to Parse.


Returns: <Boolean>
Boolean isValid( )

Checks if the model is currently in a valid state.


Returns: <Boolean>
Parse.Op op( attr )

Returns an instance of a subclass of Parse.Op describing what kind of modification has been performed on this field since the last time it was saved. For example, after calling object.increment("x"), calling object.op("x") would return an instance of Parse.Op.Increment.

Parameters:
  • attr <String>

    The key.


Returns: <Parse.Op>

The operation, or undefined if none.

registerSubclass( className, constructor )

Registers a subclass of Parse.Object with a specific class name. When objects of that class are retrieved from a query, they will be instantiated with this subclass. This is only necessary when using ES6 subclassing.

Parameters:
  • className <String>

    The class name of the subclass

  • constructor <Class>

    The subclass

relation( String )

Gets a relation on the given class for the attribute.

Parameters:
  • String <Object>

    attr The attribute to get the relation for.

remove( attr, item )

Atomically remove all instances of an object from the array associated with a given key.

Parameters:
  • attr <String>

    The key.

  • item <Object>

    The object to remove.

Parse.Promise save( options )

Set a hash of model attributes, and save the model to the server. updatedAt will be updated when the request returns. You can either call it as:

object.save();
or
object.save(null, options);
or
object.save(attrs, options);
or
object.save(key, value, options);

For example,

gameTurn.save({
player: "Jake Cutter",
diceRoll: 2
}, {
success: function(gameTurnAgain) {
// The save was successful.
},
error: function(gameTurnAgain, error) {
// The save failed.  Error is an instance of Parse.Error.
}
});
or with promises:
gameTurn.save({
player: "Jake Cutter",
diceRoll: 2
}).then(function(gameTurnAgain) {
// The save was successful.
}, function(error) {
// The save failed.  Error is an instance of Parse.Error.
});

Parameters:
  • options <Object>

    A Backbone-style callback object. Valid options are:

    • success: A Backbone-style success callback.
    • error: An Backbone-style error callback.
    • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
    • sessionToken: A valid session token, used for making a request on behalf of a specific user.

Returns: <Parse.Promise>

A promise that is fulfilled when the save completes.

saveAll( list, options )

Saves the given list of Parse.Object. If any error is encountered, stops and calls the error handler.

  Parse.Object.saveAll([object1, object2, ...], {
    success: function(list) {
      // All the objects were saved.
    },
    error: function(error) {
      // An error occurred while saving one of the objects.
    },
  });
Parameters:
  • list <Array>

    A list of Parse.Object.

  • options <Object>

    A Backbone-style callback object.

Boolean set( key, value, options )

Sets a hash of model attributes on the object.

You can call it with an object containing keys and values, or with one key and value. For example:

  gameTurn.set({
    player: player1,
    diceRoll: 2
  }, {
    error: function(gameTurnAgain, error) {
      // The set failed validation.
    }
  });

game.set("currentPlayer", player2, { error: function(gameTurnAgain, error) { // The set failed validation. } });

game.set("finished", true);

Parameters:
  • key <String>

    The key to set.

  • value <Object>

    The value to give it.

  • options <Object>

    A set of options for the set. The only supported option is error.


Returns: <Boolean>

true if the set succeeded.

Boolean setACL( acl, options )

Sets the ACL to be used for this object.

Parameters:
  • acl <Parse.ACL>

    An instance of Parse.ACL.

  • options <Object>

    Optional Backbone-like options object to be passed in to set.


Returns: <Boolean>

Whether the set passed validation.

Object toJSON( )

Returns a JSON version of the object suitable for saving to Parse.


Returns: <Object>
Object toPointer( )

Gets a Pointer referencing this Object.


Returns: <Object>
unset( attr )

Remove an attribute from the model. This is a noop if the attribute doesn't exist.

Parameters:
  • attr <String>

    The string name of an attribute.

validate( attrs )

You should not call this function directly unless you subclass Parse.Object, in which case you can override this method to provide additional validation on set and save. Your implementation should return

Parameters:
  • attrs <Object>

    The current data to validate.


Returns:

False if the data is valid. An error object otherwise.

createdAt <Date>

The first time this object was saved on the server.

id <String>

The ID of this object, unique within its class.

updatedAt <Date>

The last time this object was updated on the server.