Commit bd612715 authored by jackbravo's avatar jackbravo

toArray now can return also the record relations

parent 11bae777
......@@ -580,9 +580,25 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return $this;
}
public function toArray()
/**
* toArray
* Mimics the result of a $query->execute(array(), Doctrine::FETCH_ARRAY);
*
* @param boolean $deep
*/
public function toArray($deep = false)
{
return $this->data;
if ($deep) {
$data = array();
foreach ($this->data as $key => $record) {
$data[$key] = $record->toArray($deep);
}
return $data;
} else {
// this is preserved for backwards compatibility
// but could be replaced with above code
return $this->data;
}
}
public function getDeleteDiff()
{
......
......@@ -1111,9 +1111,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* toArray
* returns the record as an array
*
* @param boolean $deep - Return also the relations
* @return array
*/
public function toArray()
public function toArray($deep = false)
{
$a = array();
......@@ -1127,6 +1128,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$i = $this->_table->getIdentifier();
$a[$i] = $this->getIncremented();
}
if ($deep) {
foreach ($this->_references as $key => $relation) {
$a[$key] = $relation->toArray($deep);
}
}
return array_merge($a, $this->_values);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment