- Extends ORM's isNew() method to work on saved models

This commit is contained in:
Vlad
2016-08-17 21:13:15 -04:00
parent b492bcecc0
commit 42339927cf

View File

@@ -5,6 +5,7 @@ if(!defined('ABSPATH')) exit;
class Model extends \Sudzy\ValidModel {
protected $_errors;
protected $_new_record;
function __construct() {
$this->_errors = array();
@@ -36,6 +37,7 @@ class Model extends \Sudzy\ValidModel {
function save() {
$this->setTimestamp();
$this->_new_record = $this->isNew();
try {
parent::save();
} catch(\Sudzy\ValidationException $e) {
@@ -63,6 +65,12 @@ class Model extends \Sudzy\ValidModel {
return $this;
}
function isNew() {
return (isset($this->_new_record)) ?
$this->_new_record :
parent::isNew();
}
function trash() {
return $this->set_expr('deleted_at', 'NOW()')->save();
}
@@ -157,4 +165,4 @@ class Model extends \Sudzy\ValidModel {
static function getTrashed() {
return static::whereNotNull('deleted_at');
}
}
}