[Solar-svn] Revision 3068
pmjones at solarphp.com
pmjones at solarphp.com
Fri Apr 4 10:41:45 CDT 2008
Solar_Sql_Model: [CHG] Method update(), when passed a record object, now updates *only the **changed** properties*, not every property regardless of whether it changed or not. This is particularly in recognition of increment/decrement values, which may have been altered by other processes. Also, because it's possible than a update() call may end up changing no columns at all, a non-update situation on a record results merely in a record refresh, not an update per se.
Modified: trunk/Solar/Sql/Model.php
===================================================================
--- trunk/Solar/Sql/Model.php 2008-04-04 15:39:05 UTC (rev 3067)
+++ trunk/Solar/Sql/Model.php 2008-04-04 15:41:45 UTC (rev 3068)
@@ -1716,11 +1716,28 @@
// what's the primary key?
$primary = $this->_primary_col;
if ($spec instanceof Solar_Sql_Model_Record) {
- // apply record filters and convert to array, then force the
- // WHERE clause
+
+ // apply record filters
$spec->filter();
+
+ // convert to array, and retain only changed columns.
$data = $spec->toArray();
+ foreach ($data as $key => $val) {
+ if (! $spec->isChanged($key)) {
+ unset($data[$key]);
+ }
+ }
+
+ // it's possible there are no columns that changed.
+ // if so, we're done -- make it match what's at the DB.
+ if (! $data) {
+ $spec->refresh();
+ return $data;
+ }
+
+ // force the WHERE clause
$where = array("$primary = ?" => $data[$primary]);
+
} else {
// already an array
$data = $spec;
@@ -1804,11 +1821,11 @@
/**
*
- * Unerializes data values in-place based on $this->_serialize_cols.
+ * Un-serializes data values in-place based on $this->_serialize_cols.
*
- * Does not attempt to unserialize null values.
+ * Does not attempt to un-serialize null values.
*
- * If unserializing fails, stores 'null' in the data.
+ * If un-serializing fails, stores 'null' in the data.
*
* @param array &$data Record data.
*
More information about the Solar-svn
mailing list