Skip to content

Commit

Permalink
Entity and Model corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
atishhamte committed Apr 13, 2019
1 parent 8fdb125 commit c015ef1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions system/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

namespace CodeIgniter;

use CodeIgniter\Exceptions\EntityException;
use CodeIgniter\I18n\Time;
use CodeIgniter\Exceptions\CastException;

Expand Down
20 changes: 10 additions & 10 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ public function insert($data = null, bool $returnID = true)
$this->tempData = [];
}

if (empty($data))
{
throw DataException::forEmptyDataset('insert');
}

// If $data is using a custom class with public or protected
// properties representing the table elements, we need to grab
// them as an array.
Expand Down Expand Up @@ -668,11 +673,6 @@ public function insert($data = null, bool $returnID = true)

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

if (empty($data))
{
throw DataException::forEmptyDataset('insert');
}

// Must use the set() method to ensure objects get converted to arrays
$result = $this->builder()
->set($data['data'], '', $escape)
Expand Down Expand Up @@ -749,6 +749,11 @@ public function update($id = null, $data = null): bool
$this->tempData = [];
}

if (empty($data))
{
throw DataException::forEmptyDataset('update');
}

// If $data is using a custom class with public or protected
// properties representing the table elements, we need to grab
// them as an array.
Expand Down Expand Up @@ -790,11 +795,6 @@ public function update($id = null, $data = null): bool

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

if (empty($data))
{
throw DataException::forEmptyDataset('update');
}

$builder = $this->builder();

if ($id)
Expand Down

0 comments on commit c015ef1

Please sign in to comment.