From 864617c80fa1e738b8ad128fadb3443a445b6272 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 27 Mar 2024 10:03:35 +0100 Subject: [PATCH] feat(dev): Add an example for transient db entity attributes Signed-off-by: Christoph Wurst --- developer_manual/basics/storage/database.rst | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/developer_manual/basics/storage/database.rst b/developer_manual/basics/storage/database.rst index b70640026..858203164 100644 --- a/developer_manual/basics/storage/database.rst +++ b/developer_manual/basics/storage/database.rst @@ -248,6 +248,8 @@ The following types can be added for a field: * ``json`` - JSON data is automatically decoded on reading * ``datetime`` - Providing ``\DateTime()`` objects +.. _database-entity-attribute-access: + Accessing attributes ^^^^^^^^^^^^^^^^^^^^ @@ -317,6 +319,35 @@ mapping, simply override the **columnToProperty** and **propertyToColumn** metho .. _database-entity-slugs: +Transient attributes +^^^^^^^^^^^^^^^^^^^^ + +You can add attributes to an entity class that do not map to a database column. These are called *transient* because they are neither loaded from database rows nor are their values persisted. + +.. code-block:: php + :caption: lib/Db/User.php + + lastLogin; + } + + public function setLastLogin(int $lastLogin): void { + $this->lastLogin = $lastLogin; + } + } + +It is important to define getters and setters for any transient attributes. Do not use the :ref:`magic getters and setters` of attributes that map to database columns. + Slugs ^^^^^