Unconditional Delivery Listeners¶
Description¶
This operation allows registering unconditional relation event listeners for a specific data table. You can register the following types of relation listeners that get triggered when these events occur: a new relation is added to the object, an existing relation is set(modified) and an existing relation is deleted.
Methods¶
Relation Added
addAddRelationListener(relationColumnName: string, callback: (data: RTChangeRelationStatus) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
Relation Set
addSetRelationListener(relationColumnName: string, callback: (data: RTChangeRelationStatus) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
Relation Deleted
addDeleteRelationListener(relationColumnName: string, callback: (data: RTChangeRelationStatus) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
where:
Argument | Description |
---|---|
relationColumnName |
Sets the name of the column containing relations whose changes are monitored by event listeners. |
callback |
In case the event listener is triggered, it returns a callback object containing the record where a relation was added, set or deleted. |
Return Value¶
This operation does not return a value.
However, when an event listener is triggered it returns a callback object containing the record where a relation was added, set or deleted.
Examples¶
Relation Added
The example below registers a new event listener in the "Person"
data table. The listener is triggered every time a new relation is added to an object in the data table. The listener is set to monitor the "company"
column.
const personEventHandler = Backendless.Data.of('Person').rt()
const onRelationAdded = object => console.log('Ralations to companies added. Objects IDs - ', object.children )
const onError = error => console.log('Server reported an error', error)
personEventHandler.addAddRelationListener('company', onRelationAdded, onError)
Relation Set
The example below registers a new event listener in the "Person"
data table. The listener is triggered every time an existing relation is set(modified) for an object in the data table. The listener is set to monitor the "company"
column.
const personEventHandler = Backendless.Data.of('Person').rt()
const onRelationSet = object => console.log('Ralations to companies set. Objects IDs - ', object.children )
const onError = error => console.log('Server reported an error', error)
personEventHandler.addSetRelationListener('company', onRelationSet, onError)
Relation Deleted
The example below registers a new event listener in the "Person"
data table. The listener is triggered every time an existing relation is deleted from an object in the data table. The listener is set to monitor the "company"
column.
const personEventHandler = Backendless.Data.of('Person').rt()
const onRelationDelete = object => console.log('Ralations to companies deleted. Objects IDs - ', object.children)
const onError = error => console.log('Server reported an error', error)
personEventHandler.addDeleteRelationListener('company', onRelationDelete, onError)
Codeless Reference¶
where:
Argument | Description |
---|---|
id |
Unique identifier of the new event listener. |
table name |
The name of the data table where a conditional event listener must be registered. |
relation name |
Sets the name of the column containing relations whose changes are monitored by event listeners. |
parents |
Must be a list containing objectId values representing objects associated with a specific set of relations. When an array of objects is used in the invocation, the operation registers an event listener that monitors events only associated with the specified objects. |
object |
When an event listener gets triggered, the object that triggered the listener gets saved to this variable (object ) and then it can be used for other Codeless operations. |
This operation does not return a value.
However, when an event listener is triggered it saves the record from the data table where a relation was added, set or deleted to the object
variable.
Examples¶
Relation Added
The example below registers a new event listener in the "Person"
data table. The listener is triggered every time a new relation is added to the "company"
column in the data table.
Relation Set
The example below registers a new event listener in the "Person"
data table. The listener is triggered every time an existing relation is set(modified) for objects that have relations in the "company"
column of the data table.
Relation Deleted
The example below registers a new event listener in the "Person"
data table. The listener is triggered every time an existing relation is deleted from any object that has relations stored in the "company"
column.