[Solar-svn] Revision 2712
pmjones at solarphp.com
pmjones at solarphp.com
Thu Aug 16 14:09:32 CDT 2007
Branch: Solar_Sql_Model_Record:
* [BRK] Method validate() now returns bool true/false instead of throwing an exception on failure
* [BRK] Method save() now returns bool true/false instead of throwing an exception on failure
Modified: branches/orm/Solar/Sql/Model/Record.php
===================================================================
--- branches/orm/Solar/Sql/Model/Record.php 2007-08-16 19:07:50 UTC (rev 2711)
+++ branches/orm/Solar/Sql/Model/Record.php 2007-08-16 19:09:32 UTC (rev 2712)
@@ -377,6 +377,10 @@
* @param array $data An associative array of data to merge with existing
* record data.
*
+ * @return bool
+ *
+ * @todo How to tell when related saves are invalid?
+ *
*/
public function save($data = null)
{
@@ -390,15 +394,21 @@
// only save if we're not clean
if ($this->_status != 'clean') {
- // if the primary key value is not present, insert;
- // otherwise, update.
+
+ // insert or update based on primary key value
$primary = $this->_model->primary_col;
if (empty($this->$primary)) {
- $this->_model->insertRecord($this);
+ // no primary key: insert
+ $valid = $this->_model->insertRecord($this);
} else {
- $this->_model->updateRecord($this);
+ // primary key exists: update
+ $valid = $this->_model->updateRecord($this);
}
- $this->_status = 'clean';
+
+ // if not valid, return before saving related
+ if (! $valid) {
+ return $valid;
+ }
}
// now save each related, but only if instantiated
@@ -774,12 +784,12 @@
{
$filter = $this->_model->newFilterObject();
$valid = $filter->applyChain($this);
+
if (! $valid) {
$this->_status = 'invalid';
$this->_invalid = $filter->getChainInvalid();
- throw $this->_exception('ERR_INVALID', array(
- 'invalid' => $this->_invalid,
- ));
}
+
+ return $valid;
}
}
\ No newline at end of file
More information about the Solar-svn
mailing list