- Extends ORM's isNew() method to work on saved models
This commit is contained in:
@@ -5,6 +5,7 @@ if(!defined('ABSPATH')) exit;
|
|||||||
|
|
||||||
class Model extends \Sudzy\ValidModel {
|
class Model extends \Sudzy\ValidModel {
|
||||||
protected $_errors;
|
protected $_errors;
|
||||||
|
protected $_new_record;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->_errors = array();
|
$this->_errors = array();
|
||||||
@@ -36,6 +37,7 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
$this->setTimestamp();
|
$this->setTimestamp();
|
||||||
|
$this->_new_record = $this->isNew();
|
||||||
try {
|
try {
|
||||||
parent::save();
|
parent::save();
|
||||||
} catch(\Sudzy\ValidationException $e) {
|
} catch(\Sudzy\ValidationException $e) {
|
||||||
@@ -63,6 +65,12 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNew() {
|
||||||
|
return (isset($this->_new_record)) ?
|
||||||
|
$this->_new_record :
|
||||||
|
parent::isNew();
|
||||||
|
}
|
||||||
|
|
||||||
function trash() {
|
function trash() {
|
||||||
return $this->set_expr('deleted_at', 'NOW()')->save();
|
return $this->set_expr('deleted_at', 'NOW()')->save();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user