Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add undocumented Model $allowEmptyInserts #8456

Merged
merged 2 commits into from
Jan 25, 2024
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
Loading