Permalink
Browse files

Fix PropelCollection::toArray()

  • Loading branch information...
willdurand committed Sep 19, 2012
1 parent bfb8055 commit e66636c91bc7ae126951fb601bef8c6ce0642542
@@ -142,7 +142,7 @@ public function fromArray($arr)
*
* @return array
*/
- public function toArray($keyColumn = null, $usePrefix = false)
+ public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
{
$ret = array();
foreach ($this as $key => $element) {
@@ -575,4 +575,53 @@ public function __toString()
{
return (string) $this->exportTo(constant($this->getPeerClass() . '::DEFAULT_STRING_FORMAT'));
}
+
+ /**
+ * Get an array representation of the collection
+ * Each object is turned into an array and the result is returned
+ *
+ * @param string $keyColumn If null, the returned array uses an incremental index.
+ * Otherwise, the array is indexed using the specified column
+ * @param boolean $usePrefix If true, the returned array prefixes keys
+ * with the model class name ('Article_0', 'Article_1', etc).
+ * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME,
+ * BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME,
+ * BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
+ * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
+ * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
+ *
+ * <code>
+ * $bookCollection->toArray();
+ * array(
+ * 0 => array('Id' => 123, 'Title' => 'War And Peace'),
+ * 1 => array('Id' => 456, 'Title' => 'Don Juan'),
+ * )
+ * $bookCollection->toArray('Id');
+ * array(
+ * 123 => array('Id' => 123, 'Title' => 'War And Peace'),
+ * 456 => array('Id' => 456, 'Title' => 'Don Juan'),
+ * )
+ * $bookCollection->toArray(null, true);
+ * array(
+ * 'Book_0' => array('Id' => 123, 'Title' => 'War And Peace'),
+ * 'Book_1' => array('Id' => 456, 'Title' => 'Don Juan'),
+ * )
+ * </code>
+ *
+ * @return array
+ */
+ public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
+ {
+ $ret = array();
+ $keyGetterMethod = 'get' . $keyColumn;
+
+ /** @var $obj BaseObject */
+ foreach ($this as $key => $obj) {
+ $key = null === $keyColumn ? $key : $obj->$keyGetterMethod();
+ $key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
+ $ret[$key] = $obj->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
+ }
+
+ return $ret;
+ }
}
@@ -109,55 +109,6 @@ public function fromArray($arr)
}
}
- /**
- * Get an array representation of the collection
- * Each object is turned into an array and the result is returned
- *
- * @param string $keyColumn If null, the returned array uses an incremental index.
- * Otherwise, the array is indexed using the specified column
- * @param boolean $usePrefix If true, the returned array prefixes keys
- * with the model class name ('Article_0', 'Article_1', etc).
- * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME,
- * BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME,
- * BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
- * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
- * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
- *
- * <code>
- * $bookCollection->toArray();
- * array(
- * 0 => array('Id' => 123, 'Title' => 'War And Peace'),
- * 1 => array('Id' => 456, 'Title' => 'Don Juan'),
- * )
- * $bookCollection->toArray('Id');
- * array(
- * 123 => array('Id' => 123, 'Title' => 'War And Peace'),
- * 456 => array('Id' => 456, 'Title' => 'Don Juan'),
- * )
- * $bookCollection->toArray(null, true);
- * array(
- * 'Book_0' => array('Id' => 123, 'Title' => 'War And Peace'),
- * 'Book_1' => array('Id' => 456, 'Title' => 'Don Juan'),
- * )
- * </code>
- *
- * @return array
- */
- public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
- {
- $ret = array();
- $keyGetterMethod = 'get' . $keyColumn;
-
- /** @var $obj BaseObject */
- foreach ($this as $key => $obj) {
- $key = null === $keyColumn ? $key : $obj->$keyGetterMethod();
- $key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
- $ret[$key] = $obj->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
- }
-
- return $ret;
- }
-
/**
* Get an array representation of the collection
*
@@ -35,55 +35,6 @@ public function initIterator(PropelFormatter $formatter, PDOStatement $stmt)
$this->iterator = new PropelOnDemandIterator($formatter, $stmt);
}
- /**
- * Get an array representation of the collection
- * Each object is turned into an array and the result is returned
- *
- * @param string $keyColumn If null, the returned array uses an incremental index.
- * Otherwise, the array is indexed using the specified column
- * @param boolean $usePrefix If true, the returned array prefixes keys
- * with the model class name ('Article_0', 'Article_1', etc).
- * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME,
- * BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME,
- * BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
- * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
- * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
- *
- * <code>
- * $bookCollection->toArray();
- * array(
- * 0 => array('Id' => 123, 'Title' => 'War And Peace'),
- * 1 => array('Id' => 456, 'Title' => 'Don Juan'),
- * )
- * $bookCollection->toArray('Id');
- * array(
- * 123 => array('Id' => 123, 'Title' => 'War And Peace'),
- * 456 => array('Id' => 456, 'Title' => 'Don Juan'),
- * )
- * $bookCollection->toArray(null, true);
- * array(
- * 'Book_0' => array('Id' => 123, 'Title' => 'War And Peace'),
- * 'Book_1' => array('Id' => 456, 'Title' => 'Don Juan'),
- * )
- * </code>
- *
- * @return array
- */
- public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
- {
- $ret = array();
- $keyGetterMethod = 'get' . $keyColumn;
-
- /** @var $obj BaseObject */
- foreach ($this as $key => $obj) {
- $key = null === $keyColumn ? $key : $obj->$keyGetterMethod();
- $key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
- $ret[$key] = $obj->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
- }
-
- return $ret;
- }
-
/**
* Populates the collection from an array
* Each object is populated from an array and the result is stored

0 comments on commit e66636c

Please sign in to comment.