Views: 3237
Last Modified: 01.08.2022
Object can receive 3 statuses:
- new, with data never before saved in the database;
- actual, with data matching to the data stored in the database;
- modified, with data different from the data stored in the database.
You can check object status using the public read-only property state
and class constants \Bitrix\Main\ORM\Objectify\State:
use \Bitrix\Main\Test\Typography\Book;
use \Bitrix\Main\ORM\Objectify\State;
$book = new Book;
$book->setTitle('New title');
var_dump($book->state === State::RAW);
$book->save();
var_dump($book->state === State::ACTUAL);
$book->setTitle('Another one title');
var_dump($book->state === State::CHANGED);
$book->delete();
var_dump($book->state === State::RAW);
// true