[Solar-svn] Revision 2797
pmjones at solarphp.com
pmjones at solarphp.com
Fri Sep 28 21:04:13 CDT 2007
branch: Solar_Sql_Model_Filter and related
Solar_Sql_Model_Filter
----------------------
* [BRK] Is now completely empty: no methods, no properties. Exists only as a stack fallback for the Model class.
Solar_Sql_Model_Filter_ValidateConfirm
--------------------------------------
* [FIX] Now properly compares the source and confirm values; thanks, Rodrigo Moraes.
Solar_Sql_Model_Filter_ValidateUnique
-------------------------------------
* [FIX] Now uses correct SQL when the primary key is null; thanks, Rodrigo Moraes.
Modified: branches/orm/Solar/Sql/Model/Filter/ValidateConfirm.php
===================================================================
--- branches/orm/Solar/Sql/Model/Filter/ValidateConfirm.php 2007-09-29 01:50:22 UTC (rev 2796)
+++ branches/orm/Solar/Sql/Model/Filter/ValidateConfirm.php 2007-09-29 02:04:13 UTC (rev 2797)
@@ -29,10 +29,10 @@
$confirm_val = $this->_filter->getData($confirm_key);
- if ($confirm_val !== null) {
- return (bool) $value == $confirm_val;
+ if ($confirm_val === null) {
+ return true;
} else {
- return true;
+ return ($value == $confirm_val);
}
}
}
Modified: branches/orm/Solar/Sql/Model/Filter/ValidateUnique.php
===================================================================
--- branches/orm/Solar/Sql/Model/Filter/ValidateUnique.php 2007-09-29 01:50:22 UTC (rev 2796)
+++ branches/orm/Solar/Sql/Model/Filter/ValidateUnique.php 2007-09-29 02:04:13 UTC (rev 2797)
@@ -6,12 +6,12 @@
* Validates that a value for the current data key is unique among all
* model records of its inheritance type.
*
- * The default $where clause will exclude any record having the same
- * primary-key value as the current record.
+ * This will exclude any record having the same primary-key value as the
+ * current record.
*
* {{code: php
* $where = array(
- * 'id != :id',
+ * 'id != :id', // or 'id IS NOT NULL' if the ID is null
* );
* }}
*
@@ -28,22 +28,27 @@
// make sure the $where is an array
settype($where, 'array');
+ // get the record (data) model
+ $model = $this->_filter->getData()->getModel();
+
// what is the primary-key column for the record model?
- $primary = $this->_filter->model->primary_col;
+ $primary = $model->primary_col;
- // do we have an exclusionary condition yet?
- if (! $where) {
- // set a base condition to exclude the current record
+ // exclude the current record by its primary key value
+ if ($this->_filter->getData($primary) === null) {
+ $where[] = "$primary IS NOT NULL";
+ } else {
$where[] = "$primary != :$primary";
}
- // add a condition to check for uniqueness on the current column.
+ // base condition to check for uniqueness on the current column.
+ // added conditions already exist in the "where"
$key = $this->_filter->getDataKey();
$where[] = "$key = :$key";
// see if we can fetch a row, with only the primary-key column to
// reduce resource usage.
- $result = $this->_filter->model->fetchValue(array(
+ $result = $model->fetchValue(array(
'where' => $where,
'cols' => array($primary),
'bind' => $this->_filter->getData()->toArray(),
Modified: branches/orm/Solar/Sql/Model/Filter.php
===================================================================
--- branches/orm/Solar/Sql/Model/Filter.php 2007-09-29 01:50:22 UTC (rev 2796)
+++ branches/orm/Solar/Sql/Model/Filter.php 2007-09-29 02:04:13 UTC (rev 2797)
@@ -28,41 +28,4 @@
*
*/
class Solar_Sql_Model_Filter extends Solar_Filter {
-
- /**
- *
- * The Record being filtered.
- *
- * @var Solar_Sql_Model_Record
- *
- */
- public $record;
-
- /**
- *
- * The Model on which the Record being filtered is based.
- *
- * @var Solar_Sql_Model
- *
- */
- public $model;
-
- /**
- *
- * Applies the filter chain to a Record.
- *
- * @param Solar_Sql_Model_Record $model The origin model object.
- *
- * @return bool
- *
- */
- public function applyChain(&$record)
- {
- // set the record object and its model
- $this->record = $record;
- $this->model = $record->getModel();
-
- // now apply the filter chain
- return parent::applyChain($record);
- }
}
\ No newline at end of file
More information about the Solar-svn
mailing list