Added logic to prevent the empty string from entering the database, using NULL instead

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@215 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-05 23:33:07 +00:00
parent ae276d310a
commit 24245e24f1

View File

@@ -39,6 +39,7 @@
class AppModel extends Model {
var $actsAs = array('Containable', 'Linkable');
var $useNullForEmpty = true;
/**
* Get Enum Values
@@ -131,6 +132,32 @@ class AppModel extends Model {
}
function recursive_array_replace($find, $replace, &$data) {
if (!isset($data))
return;
if (is_array($data)) {
foreach ($data as $key => &$value) {
$this->recursive_array_replace($find, $replace, $value);
}
return;
}
if (isset($replace))
$data = preg_replace($find, $replace, $data);
elseif (preg_match($find, $data))
$data = null;
}
function beforeSave() {
// Replace all empty strings with NULL.
// If a particular model doesn't like this, they'll have to
// override the behavior, or set useNullForEmpty to false.
if ($this->useNullForEmpty)
$this->recursive_array_replace("/^\s*$/", null, $this->data);
return true;
}
/**************************************************************************
**************************************************************************
**************************************************************************