Skip to content

Commit

Permalink
Update ActiveRecord.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinevia authored Jun 19, 2019
1 parent 7118668 commit 372085c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ protected function update()
*/
public function delete()
{
$beforeDeleteExists = method_exists($this, 'beforeDelete'));
$beforeDeleteExists = method_exists($this, 'beforeDelete');

if ($beforeDeleteExists){
call_user_func([$this,'beforeDelete']);
}

$keys = $this->getKeys();
$db = static::getDatabase();
Expand All @@ -136,24 +140,25 @@ public function delete()
*/
public function save()
{
$beforeSaveExists = method_exists($this, 'beforeSave'));
$beforeInsertExists = method_exists($this, 'beforeInsert'));
$beforeUpdateExists = method_exists($this, 'beforeUpdate'));
$beforeSaveExists = method_exists($this, 'beforeSave');
$beforeInsertExists = method_exists($this, 'beforeInsert');
$beforeUpdateExists = method_exists($this, 'beforeUpdate');

if ($beforeSaveExists){

}

call_user_func([$this,'beforeSave']);
}

if (count($this->data_changed) == count($this->data)) {
if ($beforeInsertExists) {

call_user_func([$this,'beforeInsert']);
}

return $this->insert();
} else {
if ($beforeUpdateExists) {

call_user_func([$this,'beforeUpdate']);
}

return $this->update();
}
}
Expand Down

0 comments on commit 372085c

Please sign in to comment.