Skip to content

Commit ffb2027

Browse files
authored
Merge pull request #8456 from kenjis/add-model-allowEmptyInserts
fix: add undocumented Model $allowEmptyInserts
2 parents 13590d6 + aa66b79 commit ffb2027

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

system/Commands/Generators/Views/model.tpl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class {class} extends Model
1717
protected $protectFields = true;
1818
protected $allowedFields = [];
1919

20+
protected bool $allowEmptyInserts = false;
21+
2022
// Dates
2123
protected $useTimestamps = false;
2224
protected $dateFormat = 'datetime';

user_guide_src/source/models/model.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ potential mass assignment vulnerabilities.
157157

158158
.. note:: The `$primaryKey`_ field should never be an allowed field.
159159

160+
$allowEmptyInserts
161+
------------------
162+
163+
.. versionadded:: 4.3.0
164+
165+
Whether to allow inserting empty data. The default value is ``false``, meaning
166+
that if you try to insert empty data, an exception with
167+
"There is no data to insert." will raise.
168+
169+
You may also change this setting with the :ref:`model-allow-empty-inserts` method.
170+
160171
Dates
161172
-----
162173

@@ -371,6 +382,8 @@ You can use ``allowEmptyInserts()`` method to insert empty data. The Model throw
371382

372383
.. literalinclude:: model/056.php
373384

385+
You may also change this setting with the `$allowEmptyInserts`_ property.
386+
374387
You can enable the check again by calling ``allowEmptyInserts(false)``.
375388

376389
update()

user_guide_src/source/models/model/005.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class UserModel extends Model
1616

1717
protected $allowedFields = ['name', 'email'];
1818

19+
protected bool $allowEmptyInserts = false;
20+
1921
// Dates
2022
protected $useTimestamps = false;
2123
protected $dateFormat = 'datetime';

0 commit comments

Comments
 (0)