Session: Storing Entities

To store entities inside the session object, use one of the three store methods.

Syntax

First overload: Stores the entity in a session, then extracts the ID from the entity or generates a new one if it's not available.

public function store(?object $entity): void;

Second overload: Stores the entity in a session with given ID.

public function store(?object $entity, ?string $id): void;

Third overload: Stores the entity in a session with given ID, forces concurrency check with given change vector.

public function store(?object $entity, ?string $id, ?string $changeVector): void;
Parameters
entity object Entity that will be stored
changeVector string Entity changeVector, used for concurrency checks (null to skip check)
id string Entity will be stored under this ID, (null to generate automatically)

Example

$employee = new Employee();
$employee->setFirstName("John");
$employee->setLastName("Doe");

// generate Id automatically
$session->store($employee);

// send all pending operations to server, in this case only `Put` operation
$session->saveChanges();