$objectNew and $objectOld

The two stages of a record.

Every change is defined by before and after

Suppose you have a table of Employees. This table contains your employees' names, phone numbers and emails. One day, your employee Andrew tells you he has a new phone number. You then go to the table and update the record with this information. It'll look something like this:

800

Updating Andrew's phone number

If we think about, the record that has Andrew's information can be defined by two moments:

Before the change, the record was comprised of the following information: Name: Andrew / Phone Number: 111 222 3333 / Email: [email protected].

After the change, the record is comprised of the following information: Name: Andrew / Phone Number: 111 444 7777 / Email: [email protected].

When running automations, it can be useful to know the record's information in both states, so whenever you create, update or delete information through the interface, jestor automatically stores them into two separate variables: $objectNew and $objectOld.

πŸ“˜

Variables and Arrays

If you'd like to understand more about variables or arrays, we recommend that you check out the links below.

Variables: https://www.php.net/manual/en/language.variables.php
Arrays: https://www.php.net/manual/en/language.types.array.php

$objectNew contains all the information the record will have after creation or updating. So, in the example above, $objectNew will have the following data:

$objectNew = ['id_employees' => 1, 'name' => 'Andrew', 'phone' => '111 444 7777', 'email' => '[email protected]'];

🚧

About the record's id

Every table in jestor has a field that's not visible on the user interface: the id. The field's API/trigger name will always be id_nameofthetable. In the scenario above, Andrew is the very first record of the table Employees, so his id_employees is 1.

On a similar note, $objectOld contains all the information the record had before updating or deleting. So, in the example above, $objectOld will have the following data:

$objectOld = ['id_employees' => 1, 'name' => 'Andrew', 'phone' => '111 222 3333', 'email' => '[email protected]'];

Different scenarios

Because of their own nature, $objectNew and $objectOld do not always exist. Their existence will depend on which action the user is doing on the interface.

Creating a record: because the record didn't exist prior to the user's action, there'll be no $objectOld, only $objectNew.

Updating a record: in this scenario, there's both $objectNew and $objectOld.

Deleting a record: because the user is not sending new information for the record, there'll be no $objectNew, only $objectOld.

With this in mind, we can move on to the next core concept: triggers.