Skip to content

Commit 6b560bb

Browse files
committed
docs: fix section title marks
1 parent fbb9c4d commit 6b560bb

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

user_guide_src/source/models/entities.rst

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ be used directly with the :doc:`Model </models/model>` if that fits your needs b
1010
:local:
1111
:depth: 2
1212

13+
************
1314
Entity Usage
14-
============
15+
************
1516

1617
At its core, an Entity class is simply a class that represents a single database row. It has class properties
1718
to represent the database columns, and provides any additional methods to implement the business logic for
@@ -34,7 +35,7 @@ Assume you have a database table named ``users`` that has the following schema::
3435
.. important:: ``attributes`` is a reserved word for internal use. If you use it as a column name, the Entity does not work correctly.
3536

3637
Create the Entity Class
37-
-----------------------
38+
=======================
3839

3940
Now create a new Entity class. Since there's no default location to store these classes, and it doesn't fit
4041
in with the existing directory structure, create a new directory at **app/Entities**. Create the
@@ -45,7 +46,7 @@ Entity itself at **app/Entities/User.php**.
4546
At its simplest, this is all you need to do, though we'll make it more useful in a minute.
4647

4748
Create the Model
48-
----------------
49+
================
4950

5051
Create the model first at **app/Models/UserModel.php** so that we can interact with it:
5152

@@ -58,7 +59,7 @@ class as the ``$returnType``. This ensures that all methods on the model that re
5859
instances of our User Entity class instead of an object or array like normal.
5960

6061
Working with the Entity Class
61-
-----------------------------
62+
=============================
6263

6364
Now that all of the pieces are in place, you would work with the Entity class as you would any other class:
6465

@@ -79,7 +80,7 @@ a new row, or update an existing one.
7980
call the ``update()``, then only values that have changed are passed.
8081

8182
Filling Properties Quickly
82-
--------------------------
83+
==========================
8384

8485
The Entity class also provides a method, ``fill()`` that allows you to shove an array of key/value pairs into the class
8586
and populate the class properties. Any property in the array will be set on the Entity. However, when saving through
@@ -93,15 +94,16 @@ You can also pass the data in the constructor and the data will be passed throug
9394
.. literalinclude:: entities/005.php
9495

9596
Bulk Accessing Properties
96-
-------------------------
97+
=========================
9798

9899
The Entity class has two methods to extract all available properties into an array: ``toArray()`` and ``toRawArray()``.
99100
Using the raw version will bypass magic "getter" methods and casts. Both methods can take a boolean first parameter
100101
to specify whether returned values should be filtered by those that have changed, and a boolean final parameter to
101102
make the method recursive, in case of nested Entities.
102103

104+
***********************
103105
Handling Business Logic
104-
=======================
106+
***********************
105107

106108
While the examples above are convenient, they don't help enforce any business logic. The base Entity class implements
107109
some smart ``__get()`` and ``__set()`` methods that will check for special methods and use those instead of using
@@ -131,8 +133,9 @@ business logic and create objects that are pleasant to use.
131133

132134
.. literalinclude:: entities/007.php
133135

136+
************
134137
Data Mapping
135-
============
138+
************
136139

137140
At many points in your career, you will run into situations where the use of an application has changed and the
138141
original column names in the database no longer make sense. Or you find that your coding style prefers camelCase
@@ -168,11 +171,12 @@ to the database. However, ``unset()`` and ``isset()`` only work on the mapped pr
168171
for the database column name. In this example, you must define ``setFullName()`` and
169172
``getFullName()``.
170173

174+
********
171175
Mutators
172-
========
176+
********
173177

174178
Date Mutators
175-
-------------
179+
=============
176180

177181
By default, the Entity class will convert fields named `created_at`, `updated_at`, or `deleted_at` into
178182
:doc:`Time </libraries/time>` instances whenever they are set or retrieved. The Time class provides a large number
@@ -190,7 +194,7 @@ current timezone, as set in **app/Config/App.php**:
190194
.. _entities-property-casting:
191195

192196
Property Casting
193-
----------------
197+
================
194198

195199
You can specify that properties in your Entity should be converted to common data types with the ``$casts`` property.
196200
This option should be an array where the key is the name of the class property, and the value is the data type it
@@ -206,7 +210,7 @@ For example, if you had a User entity with an ``is_banned`` property, you can ca
206210
.. literalinclude:: entities/012.php
207211

208212
Array/Json Casting
209-
------------------
213+
==================
210214

211215
Array/Json casting is especially useful with fields that store serialized arrays or json in them. When cast as:
212216

@@ -227,7 +231,7 @@ the value whenever the property is set:
227231
.. literalinclude:: entities/014.php
228232

229233
CSV Casting
230-
-----------
234+
===========
231235

232236
If you know you have a flat array of simple values, encoding them as a serialized or JSON string
233237
may be more complex than the original structure. Casting as Comma-Separated Values (CSV) is
@@ -243,7 +247,7 @@ Stored in the database as "red,yellow,green":
243247
.. note:: Casting as CSV uses PHP's internal ``implode`` and ``explode`` methods and assumes all values are string-safe and free of commas. For more complex data casts try ``array`` or ``json``.
244248

245249
Custom casting
246-
--------------
250+
==============
247251

248252
You can define your own conversion types for getting and setting data.
249253

@@ -275,8 +279,9 @@ Additional parameters are indicated in square brackets and listed with a comma.
275279
the value ``nullable`` will be passed to the casting type handler.
276280
If casting type has predefined parameters, then ``nullable`` will be added to the end of the list.
277281

282+
*******************************
278283
Checking for Changed Attributes
279-
===============================
284+
*******************************
280285

281286
You can check if an Entity attribute has changed since it was created. The only parameter is the name of the
282287
attribute to check:

0 commit comments

Comments
 (0)