Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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