Skip to content

Commit 4c7ca62

Browse files
authored
Merge pull request #8587 from kenjis/docs-improve-model-entity
docs: improve Model and Entity
2 parents 67436e3 + a5be00b commit 4c7ca62

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

user_guide_src/source/models/entities.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,21 @@ Create the model first at **app/Models/UserModel.php** so that we can interact w
6060

6161
.. literalinclude:: entities/002.php
6262

63-
The model uses the ``users`` table in the database for all of its activities. We've set the ``$allowedFields`` property
64-
to include all of the fields that we want outside classes to change. The ``id``, ``created_at``, and ``updated_at`` fields
65-
are handled automatically by the class or the database, so we don't want to change those. Finally, we've set our Entity
66-
class as the ``$returnType``. This ensures that all methods on the model that return rows from the database will return
63+
The model uses the ``users`` table in the database for all of its activities.
64+
65+
We've set the ``$allowedFields`` property to include all of the fields that we
66+
want outside classes to change. The ``id``, ``created_at``, and ``updated_at``
67+
fields are handled automatically by the class or the database, so we don't want
68+
to change those.
69+
70+
Finally, we've set our Entity class as the ``$returnType``. This ensures that all
71+
built-in methods on the model that return rows from the database will return
6772
instances of our User Entity class instead of an object or array like normal.
6873

74+
.. note::
75+
Of course, if you add a custom method to your model, you must implement it
76+
so that instances of ``$returnType`` are returned.
77+
6978
Working with the Entity Class
7079
=============================
7180

user_guide_src/source/models/model.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,16 @@ default value is ``true``.
123123
$returnType
124124
-----------
125125

126-
The Model's CRUD methods will take a step of work away from you and automatically return
127-
the resulting data, instead of the Result object. This setting allows you to define
128-
the type of data that is returned. Valid values are '**array**' (the default), '**object**', or the **fully
129-
qualified name of a class** that can be used with the Result object's ``getCustomResultObject()``
130-
method. Using the special ``::class`` constant of the class will allow most IDEs to
131-
auto-complete the name and allow functions like refactoring to better understand your code.
126+
The Model's **find*()** methods will take a step of work away from you and automatically
127+
return the resulting data, instead of the Result object.
128+
129+
This setting allows you to define the type of data that is returned. Valid values
130+
are '**array**' (the default), '**object**', or the **fully qualified name of a class**
131+
that can be used with the Result object's ``getCustomResultObject()`` method.
132+
133+
Using the special ``::class`` constant of the class will allow most IDEs to
134+
auto-complete the name and allow functions like refactoring to better understand
135+
your code.
132136

133137
.. _model-use-soft-deletes:
134138

@@ -145,7 +149,7 @@ This requires either a DATETIME or INTEGER field in the database as per the mode
145149
`$dateFormat`_ setting. The default field name is ``deleted_at`` however this name can be
146150
configured to any name of your choice by using `$deletedField`_ property.
147151

148-
.. important:: The ``deleted_at`` field must be nullable.
152+
.. important:: The ``deleted_at`` field in the database must be nullable.
149153

150154
$allowedFields
151155
--------------

0 commit comments

Comments
 (0)