Views: 3337
Last Modified: 30.03.2022
  • set

    Setting value is performed in the familiar manner:

    $book = \Bitrix\Main\Test\Typography\BookTable::getByPrimary(1)
    	->fetchObject();
    
    $book->setTitle("New title");
    

    The object memorizes its original values. From this moment, the current value can be accessed via the main "getter" get and the database original/actual value can be accessed via auxiliary "getter" method remindActual:

    $book->getTitle(); // current value
    $book->remindActualTitle(); // actual database value
    

    Primary key can be set only in new objects, you cannot update it in existing objects. When it's needed, you have to create a new object and delete the old one. Also, Bitrix\Main\ORM\Fields\ExpressionField fields cannot be set due to values being calculated automatically and cannot be modified from outside.

    When setting a value different from the current value, such value won't be modified and won't be included into SQL query when saving the object.
  • reset

    To cancel the new value and rollback to the old one, you can use the auxiliary "setter" method reset:

    $book = \Bitrix\Main\Test\Typography\BookTable::getByPrimary(1)
    	->fetchObject();
    
    echo $book->getTitle();
    // prints "Title 1"
    
    $book->setTitle("New title");
    
    echo $book->getTitle();
    // prints "New title"
    
    $book->resetTitle();
    
    echo $book->getTitle();
    // prints "Title 1"
    
  • unset

    One more auxiliary "setter" method unset deletes object as if it wasn't retrieved from the database and wasn't set at all:

    $book = \Bitrix\Main\Test\Typography\BookTable::getByPrimary(1)
    	->fetchObject();
    
    echo $book->getTitle();
    // prints "Title 1"
    
    $book->unsetTitle();
    
    echo $book->getTitle();
    // null
    

    "Setter" methods also have universal variants for calling with field title as an argument:

    $fieldName = 'TITLE';
    
    $book->set($fieldName, "New title");
    $book->reset($fieldName);
    $book->unset($fieldName);
    
    All actions to update the value result in updates during session only. Read more about how to save the object to register modifications in the database here: Create and edit (save, new).




Courses developed by Bitrix24