From bf6ebaa58f1832fe5bd3f0f944f106b295b42e11 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 27 Nov 2023 09:03:43 +0900 Subject: [PATCH 1/3] docs: remove "in it's database layer" Entity can be used for data from non-database. --- user_guide_src/source/models/entities.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/models/entities.rst b/user_guide_src/source/models/entities.rst index f1f8b42c8a62..1b91bed7b443 100644 --- a/user_guide_src/source/models/entities.rst +++ b/user_guide_src/source/models/entities.rst @@ -2,7 +2,7 @@ Using Entity Classes ##################### -CodeIgniter supports Entity classes as a first-class citizen in it's database layer, while keeping +CodeIgniter supports Entity classes as a first-class citizen, while keeping them completely optional to use. They are commonly used as part of the Repository pattern, but can be used directly with the :doc:`Model ` if that fits your needs better. From 2c3ab28430e7f7f2097e3fa734354146a2c826de Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 27 Nov 2023 09:06:16 +0900 Subject: [PATCH 2/3] docs: add note for non-database usage --- user_guide_src/source/models/entities.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/models/entities.rst b/user_guide_src/source/models/entities.rst index 1b91bed7b443..7153c459c2e4 100644 --- a/user_guide_src/source/models/entities.rst +++ b/user_guide_src/source/models/entities.rst @@ -16,9 +16,17 @@ Entity Usage At its core, an Entity class is simply a class that represents a single database row. It has class properties to represent the database columns, and provides any additional methods to implement the business logic for -that row. The core feature, though, is that it doesn't know anything about how to persist itself. That's the +that row. + +.. note:: For ease of understanding, the explanation here is based on the case of + using a database. However, Entity can also be used for data that does not come + from a database. + +The core feature, though, is that it doesn't know anything about how to persist itself. That's the responsibility of the model or the repository class. That way, if anything changes on how you need to save the -object, you don't have to change how that object is used throughout the application. This makes it possible to +object, you don't have to change how that object is used throughout the application. + +This makes it possible to use JSON or XML files to store the objects during a rapid prototyping stage, and then easily switch to a database when you've proven the concept works. From 544093acc87bdc50e6dd94f0bebabb4aefacf7e9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 27 Nov 2023 09:06:46 +0900 Subject: [PATCH 3/3] docs: make description more detailed --- user_guide_src/source/models/entities.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/models/entities.rst b/user_guide_src/source/models/entities.rst index 7153c459c2e4..072d41e85793 100644 --- a/user_guide_src/source/models/entities.rst +++ b/user_guide_src/source/models/entities.rst @@ -78,7 +78,7 @@ access them as if they were public properties. The base class, ``CodeIgniter\Ent well as providing the ability to check the properties with ``isset()``, or ``unset()`` the property, and keep track of what columns have changed since the object was created or pulled from the database. -.. note:: The Entity class stores the data in the property ``$attributes``. +.. note:: The Entity class stores the data in the class property ``$attributes`` internally. When the User is passed to the model's ``save()`` method, it automatically takes care of reading the properties and saving any changes to columns listed in the model's ``$allowedFields`` property. It also knows whether to create