Realm.Object

Realm objects will automatically inherit from this class unless a Realm~ObjectClass was specified that does not inherit from this class.

Since: 0.12.0
addListener(callback)

Add a listener callback which will be called when a live object instance changes.

Parameters:
  • callback
    • Type: function
    • A function to be called when changes occur. The callback function is called with two arguments:

      • obj: the object that changed,
      • changes: a dictionary with keys deleted, and changedProperties. deleted is true if the object has been deleted. changesProperties is an array of properties that have changed their value.
Throws:
  • Error
    • If callback is not a function.

Example:
wine.addListener((obj, changes) => {
 // obj === wine
 console.log(`object is deleted: ${changes.deleted}`);
 console.log(`${changes.changedProperties.length} properties have been changed:`);
 changes.changedProperties.forEach(prop => {
     console.log(` ${prop}`);
  });
})
getPropertyType(propertyName)string

Get underlying type of a property value.

Parameters:
  • propertyName
    • Type: string
    • The name of the property to retrieve the type of.

Throws:
  • Error
    • If property does not exist.

Returns: string Underlying type of the property value.
isValid()boolean

Checks if this object has not been deleted and is part of a valid Realm.

Returns: boolean indicating if the object can be safely accessed.
linkingObjects(objectType, property)Realm.Results

Returns all the objects that link to this object in the specified relationship.

Parameters:
  • objectType
    • Type: string
    • The type of the objects that link to this object's type.

  • property
    • Type: string
    • The name of the property that references objects of this object's type.

Throws:
  • Error
    • If the relationship is not valid.

Returns: Realm.Results the objects that link to this object.
linkingObjectsCount()number

Returns the total count of incoming links to this object

Returns: number number of links to this object.
objectSchema()ObjectSchema

Returns the schema for the type this object belongs to.

Returns: ObjectSchema the schema that describes this object.
removeAllListeners()

Remove all listeners.

removeListener(callback)

Remove the listener callback

Parameters:
  • callback
    • Type: function
    • A function previously added as listener