Skip to content

Commit

Permalink
Merge pull request #8456 from kenjis/add-model-allowEmptyInserts
Browse files Browse the repository at this point in the history
fix: add undocumented Model $allowEmptyInserts
  • Loading branch information
kenjis authored Jan 25, 2024
2 parents 13590d6 + aa66b79 commit ffb2027
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions system/Commands/Generators/Views/model.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class {class} extends Model
protected $protectFields = true;
protected $allowedFields = [];

protected bool $allowEmptyInserts = false;

// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
Expand Down
13 changes: 13 additions & 0 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ potential mass assignment vulnerabilities.

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

$allowEmptyInserts
------------------

.. versionadded:: 4.3.0

Whether to allow inserting empty data. The default value is ``false``, meaning
that if you try to insert empty data, an exception with
"There is no data to insert." will raise.

You may also change this setting with the :ref:`model-allow-empty-inserts` method.

Dates
-----

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

.. literalinclude:: model/056.php

You may also change this setting with the `$allowEmptyInserts`_ property.

You can enable the check again by calling ``allowEmptyInserts(false)``.

update()
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/models/model/005.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class UserModel extends Model

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

protected bool $allowEmptyInserts = false;

// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
Expand Down

0 comments on commit ffb2027

Please sign in to comment.