Constructor
new ParseObject(className, attributes, options)
Parameters:
Name | Type | Description |
---|---|---|
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. |
Members
attributes
Prototype getters / setters
createdAt
The first time this object was saved on the server.
Properties:
Name | Type | Description |
---|---|---|
createdAt |
Date
|
updatedAt
The last time this object was updated on the server.
Properties:
Name | Type | Description |
---|---|---|
updatedAt |
Date
|
Methods
(static) _clearAllState()
Static methods
(static) createWithoutData(id) → {Parse.Object}
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:
Name | Type | Description |
---|---|---|
id |
string
|
The ID of the object to create a reference to. |
(static) destroyAll(list, options) → {Promise}
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, ...]) .then((list) => { // All the objects were deleted. }, (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:
Name | Type | Description |
---|---|---|
list |
Array
|
A list of |
options |
object
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the destroyAll completes.
(static) 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.
(static) 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.
(static) extend(className, protoProps, classProps) → {Parse.Object}
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:
Name | Type | Description |
---|---|---|
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. |
(static) fetchAll(list, options) → {Array.<Parse.Object>}
Fetches the given list of Parse.Object. If any error is encountered, stops and calls the error handler.
Parse.Object.fetchAll([object1, object2, ...]) .then((list) => { // All the objects were fetched. }, (error) => { // An error occurred while fetching one of the objects. });
Parameters:
Name | Type | Description |
---|---|---|
list |
Array
|
A list of |
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Array.<Parse.Object>
(static) fetchAllIfNeeded(list, options) → {Array.<Parse.Object>}
Fetches the given list of Parse.Object if needed. If any error is encountered, stops and calls the error handler.
Parse.Object.fetchAllIfNeeded([object1, ...]) .then((list) => { // Objects were fetched and updated. }, (error) => { // An error occurred while fetching one of the objects. });
Parameters:
Name | Type | Description |
---|---|---|
list |
Array
|
A list of |
options |
object
|
Returns:
- Type:
-
Array.<Parse.Object>
(static) fetchAllIfNeededWithInclude(list, keys, options) → {Array.<Parse.Object>}
Fetches the given list of Parse.Object if needed. If any error is encountered, stops and calls the error handler.
Includes nested Parse.Objects for the provided key. You can use dot notation to specify which fields in the included object are also fetched.
If any error is encountered, stops and calls the error handler.
Parse.Object.fetchAllIfNeededWithInclude([object1, object2, ...], [pointer1, pointer2, ...]) .then((list) => { // All the objects were fetched. }, (error) => { // An error occurred while fetching one of the objects. });
Parameters:
Name | Type | Description |
---|---|---|
list |
Array
|
A list of |
keys |
string
|
Array.<(string|Array.<string>)>
|
The name(s) of the key(s) to include. |
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Array.<Parse.Object>
(static) fetchAllWithInclude(list, keys, options) → {Array.<Parse.Object>}
Fetches the given list of Parse.Object.
Includes nested Parse.Objects for the provided key. You can use dot notation to specify which fields in the included object are also fetched.
If any error is encountered, stops and calls the error handler.
Parse.Object.fetchAllWithInclude([object1, object2, ...], [pointer1, pointer2, ...]) .then((list) => { // All the objects were fetched. }, (error) => { // An error occurred while fetching one of the objects. });
Parameters:
Name | Type | Description |
---|---|---|
list |
Array
|
A list of |
keys |
string
|
Array.<(string|Array.<string>)>
|
The name(s) of the key(s) to include. |
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Array.<Parse.Object>
(static) fromJSON(json, override, dirty) → {Parse.Object}
Creates a new instance of a Parse Object from a JSON representation.
Parameters:
Name | Type | Description |
---|---|---|
json |
object
|
The JSON map of the Object's data |
override |
boolean
|
In single instance mode, all old server data is overwritten if this is set to true |
dirty |
boolean
|
Whether the Parse.Object should set JSON keys to dirty |
(static) pinAll(objects) → {Promise}
Asynchronously stores the objects and every object they point to in the local datastore, recursively, using a default pin name: _default.
If those other objects have not been fetched from Parse, they will not be stored. However, if they have changed data, all the changes will be retained.
await Parse.Object.pinAll([...]);
To retrieve object:
query.fromLocalDatastore()
or query.fromPin()
Parameters:
Name | Type | Description |
---|---|---|
objects |
Array
|
A list of |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the pin completes.
(static) pinAllWithName(name, objects) → {Promise}
Asynchronously stores the objects and every object they point to in the local datastore, recursively.
If those other objects have not been fetched from Parse, they will not be stored. However, if they have changed data, all the changes will be retained.
await Parse.Object.pinAllWithName(name, [obj1, obj2, ...]);
To retrieve object:
query.fromLocalDatastore()
or query.fromPinWithName(name)
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
objects |
Array
|
A list of |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the pin completes.
(static) 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:
Name | Type | Description |
---|---|---|
className |
string
|
The class name of the subclass |
constructor |
function
|
The subclass |
(static) saveAll(list, options) → {Array.<Parse.Object>}
Saves the given list of Parse.Object. If any error is encountered, stops and calls the error handler.
Parse.Object.saveAll([object1, object2, ...]) .then((list) => { // All the objects were saved. }, (error) => { // An error occurred while saving one of the objects. });
Parameters:
Name | Type | Description |
---|---|---|
list |
Array
|
A list of |
options |
object
|
Returns:
- Type:
-
Array.<Parse.Object>
(static) unPinAll(objects) → {Promise}
Asynchronously removes the objects and every object they point to in the local datastore, recursively, using a default pin name: _default.
await Parse.Object.unPinAll([...]);
Parameters:
Name | Type | Description |
---|---|---|
objects |
Array
|
A list of |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
(static) unPinAllObjects() → {Promise}
Asynchronously removes all objects in the local datastore using a default pin name: _default.
await Parse.Object.unPinAllObjects();
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
(static) unPinAllObjectsWithName(name) → {Promise}
Asynchronously removes all objects with the specified pin name. Deletes the pin name also.
await Parse.Object.unPinAllObjectsWithName(name);
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
(static) unPinAllWithName(name, objects) → {Promise}
Asynchronously removes the objects and every object they point to in the local datastore, recursively.
await Parse.Object.unPinAllWithName(name, [obj1, obj2, ...]);
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
objects |
Array
|
A list of |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
(static) unregisterSubclass(className)
Unegisters a subclass of Parse.Object with a specific class name.
Parameters:
Name | Type | Description |
---|---|---|
className |
string
|
The class name of the subclass |
_clearPendingOps(keysToClearopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keysToClear |
Array.<string>
|
<optional> |
if specified, only ops matching these fields will be cleared |
_getId() → {string}
Returns a local or server Id used uniquely identify this object
Returns:
- Type:
-
string
_getStateIdentifier() → {Parse.Object|object}
Returns a unique identifier used to pull data from the State Controller.
Returns:
- Type:
-
Parse.Object
|object
add(attr, item) → {ParseObject|boolean}
Atomically add an object to the end of the array associated with a given key.
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The item to add. |
Returns:
- Type:
-
ParseObject
|boolean
addAll(attr, items) → {ParseObject|boolean}
Atomically add the objects to the end of the array associated with a given key.
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The items to add. |
Returns:
- Type:
-
ParseObject
|boolean
addAllUnique(attr, items) → {ParseObject|boolean}
Atomically add the objects 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:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The objects to add. |
Returns:
- Type:
-
ParseObject
|boolean
addUnique(attr, item) → {ParseObject|boolean}
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:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The object to add. |
Returns:
- Type:
-
ParseObject
|boolean
clear() → {ParseObject|boolean}
Clears all attributes on a model
Returns:
- Type:
-
ParseObject
|boolean
clone() → {Parse.Object}
Creates a new model with identical attributes to this one.
Returns:
- Type:
-
Parse.Object
decrement(attr, amount) → {ParseObject|boolean}
Atomically decrements the value of the given attribute the next time the object is saved. If no amount is specified, 1 is used by default.
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
amount |
Number
|
The amount to decrement by (optional). |
Returns:
- Type:
-
ParseObject
|boolean
destroy(options) → {Promise}
Destroy this model on the server if it was already persisted.
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the destroy completes.
(async) destroyEventually(optionsopt) → {Promise}
Deletes this object from the server at some unspecified time in the future, even if Parse is currently inaccessible.
Use this when you may not have a solid network connection, and don't need to know when the delete completes. If there is some problem with the object such that it can't be deleted, the request will be silently discarded.
Delete instructions made with this method will be stored locally in an on-disk cache until they can be transmitted to Parse. They will be sent immediately if possible. Otherwise, they will be sent the next time a network connection is available. Delete requests will persist even after the app is closed, in which case they will be sent the next time the app is opened.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object
|
<optional> |
Valid options are:
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the destroy completes.
dirty(attr) → {boolean}
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:
Name | Type | Description |
---|---|---|
attr |
string
|
An attribute name (optional). |
Returns:
- Type:
-
boolean
dirtyKeys() → {Array.<string>}
Returns an array of keys that have been modified since last save/refresh
Returns:
- Type:
-
Array.<string>
equals(other) → {boolean}
Determines whether this ParseObject is equal to another ParseObject
Parameters:
Name | Type | Description |
---|---|---|
other |
object
|
An other object ot compare |
Returns:
- Type:
-
boolean
escape(attr) → {string}
Gets the HTML-escaped value of an attribute.
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of an attribute. |
Returns:
- Type:
-
string
existed() → {boolean}
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:
- Type:
-
boolean
(async) exists(options) → {Promise.<boolean>}
Returns true if this object exists on the Server
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Promise.<boolean>
A boolean promise that is fulfilled if object exists.
fetch(options) → {Promise}
Fetch the model from the server. If the server's representation of the model differs from its current attributes, they will be overriden.
Parameters:
Name | Type | Description |
---|---|---|
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the fetch completes.
(async) fetchFromLocalDatastore() → {Promise}
Asynchronously loads data from the local datastore into this object.
await object.fetchFromLocalDatastore();
You can create an unfetched pointer with Parse.Object.createWithoutData()
and then call fetchFromLocalDatastore()
on it.
Returns:
- Type:
-
Promise
A promise that is fulfilled when the fetch completes.
fetchWithInclude(keys, options) → {Promise}
Fetch the model from the server. If the server's representation of the model differs from its current attributes, they will be overriden.
Includes nested Parse.Objects for the provided key. You can use dot notation to specify which fields in the included object are also fetched.
Parameters:
Name | Type | Description |
---|---|---|
keys |
string
|
Array.<(string|Array.<string>)>
|
The name(s) of the key(s) to include. |
options |
object
|
Valid options are:
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the fetch completes.
get(attr) → {*}
Gets the value of an attribute.
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of an attribute. |
Returns:
- Type:
-
*
has(attr) → {boolean}
Returns true
if the attribute contains a value that is not
null or undefined.
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of the attribute. |
Returns:
- Type:
-
boolean
increment(attr, amount) → {ParseObject|boolean}
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:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
amount |
Number
|
The amount to increment by (optional). |
Returns:
- Type:
-
ParseObject
|boolean
initialize()
Public methods
isDataAvailable() → {boolean}
Returns true if the object has been fetched.
Returns:
- Type:
-
boolean
isNew() → {boolean}
Returns true if this object has never been saved to Parse.
Returns:
- Type:
-
boolean
(async) isPinned() → {Promise.<boolean>}
Asynchronously returns if the object is pinned
const isPinned = await object.isPinned();
Returns:
- Type:
-
Promise.<boolean>
A boolean promise that is fulfilled if object is pinned.
isValid() → {boolean}
Checks if the model is currently in a valid state.
Returns:
- Type:
-
boolean
newInstance() → {Parse.Object}
Creates a new instance of this object. Not to be confused with clone()
Returns:
- Type:
-
Parse.Object
op(attr) → {Parse.Op}
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:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
Returns:
- Type:
-
Parse.Op
The operation, or undefined if none.
pin() → {Promise}
Asynchronously stores the object and every object it points to in the local datastore, recursively, using a default pin name: _default.
If those other objects have not been fetched from Parse, they will not be stored. However, if they have changed data, all the changes will be retained.
await object.pin();
To retrieve object:
query.fromLocalDatastore()
or query.fromPin()
Returns:
- Type:
-
Promise
A promise that is fulfilled when the pin completes.
pinWithName(name) → {Promise}
Asynchronously stores the objects and every object they point to in the local datastore, recursively.
If those other objects have not been fetched from Parse, they will not be stored. However, if they have changed data, all the changes will be retained.
await object.pinWithName(name);
To retrieve object:
query.fromLocalDatastore()
or query.fromPinWithName(name)
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the pin completes.
relation(attr) → {Parse.Relation}
Gets a relation on the given class for the attribute.
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The attribute to get the relation for. |
Returns:
- Type:
-
Parse.Relation
remove(attr, item) → {ParseObject|boolean}
Atomically remove all instances of an object from the array associated with a given key.
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
item |
The object to remove. |
Returns:
- Type:
-
ParseObject
|boolean
removeAll(attr, items) → {ParseObject|boolean}
Atomically remove all instances of the objects from the array associated with a given key.
Parameters:
Name | Type | Description |
---|---|---|
attr |
String
|
The key. |
items |
Array.<Object>
|
The object to remove. |
Returns:
- Type:
-
ParseObject
|boolean
revert(…keysopt)
Clears any (or specific) changes to this object made since the last call to save()
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keys |
string
|
<optional> <repeatable> |
specify which fields to revert |
save(arg1opt, arg2opt, arg3opt) → {Promise}
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(attrs);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 }).then(function(gameTurnAgain) { // The save was successful. }, function(error) { // The save failed. Error is an instance of Parse.Error. });
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arg1 |
string
|
object
|
null
|
<optional> |
Valid options are:
|
arg2 |
string
|
object
|
<optional> |
|
arg3 |
object
|
<optional> |
Used to pass option parameters to method if arg1 and arg2 were both passed as strings. Valid options are:
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the save completes.
(async) saveEventually(optionsopt) → {Promise}
Saves this object to the server at some unspecified time in the future, even if Parse is currently inaccessible.
Use this when you may not have a solid network connection, and don't need to know when the save completes. If there is some problem with the object such that it can't be saved, it will be silently discarded.
Objects saved with this method will be stored locally in an on-disk cache until they can be delivered to Parse. They will be sent immediately if possible. Otherwise, they will be sent the next time a network connection is available. Objects saved this way will persist even after the app is closed, in which case they will be sent the next time the app is opened.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object
|
<optional> |
Used to pass option parameters to method if arg1 and arg2 were both passed as strings. Valid options are:
|
Returns:
- Type:
-
Promise
A promise that is fulfilled when the save completes.
set(key, value, options) → {ParseObject|boolean}
Sets a hash of model attributes on the object.
You can call it with an object containing keys and values, with one key and value, or dot notation. 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);
game.set("player.score", 10);
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
object
|
The key to set. |
value |
string
|
object
|
The value to give it. |
options |
object
|
A set of options for the set.
The only supported option is |
Returns:
- Type:
-
ParseObject
|boolean
true if the set succeeded.
setACL(acl, options) → {ParseObject|boolean}
Sets the ACL to be used for this object.
- See:
Parameters:
Name | Type | Description |
---|---|---|
acl |
Parse.ACL
|
An instance of Parse.ACL. |
options |
object
|
Returns:
- Type:
-
ParseObject
|boolean
Whether the set passed validation.
toJSON(seen, offline) → {object}
Returns a JSON version of the object suitable for saving to Parse.
Parameters:
Name | Type | Description |
---|---|---|
seen |
||
offline |
Returns:
- Type:
-
object
toOfflinePointer() → {Pointer}
Gets a Pointer referencing this Object.
Returns:
- Type:
-
Pointer
toPointer() → {Pointer}
Gets a Pointer referencing this Object.
Returns:
- Type:
-
Pointer
unPin() → {Promise}
Asynchronously removes the object and every object it points to in the local datastore, recursively, using a default pin name: _default.
await object.unPin();
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
unPinWithName(name) → {Promise}
Asynchronously removes the object and every object it points to in the local datastore, recursively.
await object.unPinWithName(name);
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of Pin. |
Returns:
- Type:
-
Promise
A promise that is fulfilled when the unPin completes.
unset(attr, options) → {ParseObject|boolean}
Remove an attribute from the model. This is a noop if the attribute doesn't exist.
Parameters:
Name | Type | Description |
---|---|---|
attr |
string
|
The string name of an attribute. |
options |
Returns:
- Type:
-
ParseObject
|boolean
validate(attrs) → {Parse.Error|boolean}
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
- See:
Parameters:
Name | Type | Description |
---|---|---|
attrs |
object
|
The current data to validate. |