[Solar-svn] Revision 2952
pmjones at solarphp.com
pmjones at solarphp.com
Fri Nov 16 10:47:12 CST 2007
Solar_Sql_Model_Collection: [FIX] Override Solar_Struct::load() so that fetchAssoc() keys are not renumbered. This means that load() now replaces previous collection data, instead of merging with previous data.
Modified: trunk/Solar/Sql/Model/Collection.php
===================================================================
--- trunk/Solar/Sql/Model/Collection.php 2007-11-16 03:30:18 UTC (rev 2951)
+++ trunk/Solar/Sql/Model/Collection.php 2007-11-16 16:47:12 UTC (rev 2952)
@@ -110,6 +110,33 @@
/**
*
+ * Loads the struct with data from an array or another struct.
+ *
+ * This is a complete override from the parent load() method.
+ *
+ * We need this so that fetchAssoc() loading works properly; otherwise,
+ * integer keys get renumbered, which disconnects the association.
+ *
+ * @param array|Solar_Struct $spec The data to load into the object.
+ *
+ * @return void
+ *
+ */
+ public function load($spec)
+ {
+ // force to array
+ if ($spec instanceof Solar_Struct) {
+ // we can do this because $spec is of the same class
+ $this->_data = $spec->_data;
+ } elseif (is_array($spec)) {
+ $this->_data = $spec;
+ } else {
+ $this->_data = array();
+ }
+ }
+
+ /**
+ *
* Loads *related* data for the collection.
*
* Applies particularly to has-many eager loading.
@@ -130,9 +157,9 @@
{
$related = $this->_model->getRelated($name);
if ($related->type == 'has_many') {
- foreach ($data as $item) {
- $id = array_shift($item);
- $this->_related[$name][$id][] = $item;
+ foreach ($data as $key => $val) {
+ $id = array_shift($val);
+ $this->_related[$name][$id][$key] = $val;
}
} else {
$id = array_shift($data);
More information about the Solar-svn
mailing list