Skip to content

Commit c015ef1

Browse files
committed
Entity and Model corrections
1 parent 8fdb125 commit c015ef1

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

system/Entity.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
namespace CodeIgniter;
4040

41+
use CodeIgniter\Exceptions\EntityException;
4142
use CodeIgniter\I18n\Time;
4243
use CodeIgniter\Exceptions\CastException;
4344

system/Model.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ public function insert($data = null, bool $returnID = true)
619619
$this->tempData = [];
620620
}
621621

622+
if (empty($data))
623+
{
624+
throw DataException::forEmptyDataset('insert');
625+
}
626+
622627
// If $data is using a custom class with public or protected
623628
// properties representing the table elements, we need to grab
624629
// them as an array.
@@ -668,11 +673,6 @@ public function insert($data = null, bool $returnID = true)
668673

669674
$data = $this->trigger('beforeInsert', ['data' => $data]);
670675

671-
if (empty($data))
672-
{
673-
throw DataException::forEmptyDataset('insert');
674-
}
675-
676676
// Must use the set() method to ensure objects get converted to arrays
677677
$result = $this->builder()
678678
->set($data['data'], '', $escape)
@@ -749,6 +749,11 @@ public function update($id = null, $data = null): bool
749749
$this->tempData = [];
750750
}
751751

752+
if (empty($data))
753+
{
754+
throw DataException::forEmptyDataset('update');
755+
}
756+
752757
// If $data is using a custom class with public or protected
753758
// properties representing the table elements, we need to grab
754759
// them as an array.
@@ -790,11 +795,6 @@ public function update($id = null, $data = null): bool
790795

791796
$data = $this->trigger('beforeUpdate', ['id' => $id, 'data' => $data]);
792797

793-
if (empty($data))
794-
{
795-
throw DataException::forEmptyDataset('update');
796-
}
797-
798798
$builder = $this->builder();
799799

800800
if ($id)

0 commit comments

Comments
 (0)