diff --git a/system/Commands/Generators/Views/model.tpl.php b/system/Commands/Generators/Views/model.tpl.php index b9b9c99eb560..72509cdbd9d4 100644 --- a/system/Commands/Generators/Views/model.tpl.php +++ b/system/Commands/Generators/Views/model.tpl.php @@ -17,6 +17,8 @@ class {class} extends Model protected $protectFields = true; protected $allowedFields = []; + protected bool $allowEmptyInserts = false; + // Dates protected $useTimestamps = false; protected $dateFormat = 'datetime'; diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index fdedcc7d15d7..74225cd7869c 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -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 ----- @@ -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() diff --git a/user_guide_src/source/models/model/005.php b/user_guide_src/source/models/model/005.php index c54aa69c05a8..956870af2969 100644 --- a/user_guide_src/source/models/model/005.php +++ b/user_guide_src/source/models/model/005.php @@ -16,6 +16,8 @@ class UserModel extends Model protected $allowedFields = ['name', 'email']; + protected bool $allowEmptyInserts = false; + // Dates protected $useTimestamps = false; protected $dateFormat = 'datetime';