From cadc6f8d755b0d3a7eec6c44d4cd79282952f83c Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 25 Jan 2024 18:45:22 +0900 Subject: [PATCH 1/2] docs: add missing $allowEmptyInserts --- user_guide_src/source/models/model.rst | 13 +++++++++++++ user_guide_src/source/models/model/005.php | 2 ++ 2 files changed, 15 insertions(+) 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'; From aa66b793bb1c8067d832c6a9f8206ef1eecca1e7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 25 Jan 2024 18:52:06 +0900 Subject: [PATCH 2/2] fix: add missing $allowEmptyInserts to template --- system/Commands/Generators/Views/model.tpl.php | 2 ++ 1 file changed, 2 insertions(+) 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';