Commit bd612715 authored by jackbravo's avatar jackbravo

toArray now can return also the record relations

parent 11bae777
...@@ -580,10 +580,26 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -580,10 +580,26 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return $this; 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)
{ {
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; return $this->data;
} }
}
public function getDeleteDiff() public function getDeleteDiff()
{ {
return array_diff($this->_snapshot, $this->data); return array_diff($this->_snapshot, $this->data);
......
...@@ -1111,9 +1111,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1111,9 +1111,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* toArray * toArray
* returns the record as an array * returns the record as an array
* *
* @param boolean $deep - Return also the relations
* @return array * @return array
*/ */
public function toArray() public function toArray($deep = false)
{ {
$a = array(); $a = array();
...@@ -1127,6 +1128,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1127,6 +1128,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$i = $this->_table->getIdentifier(); $i = $this->_table->getIdentifier();
$a[$i] = $this->getIncremented(); $a[$i] = $this->getIncremented();
} }
if ($deep) {
foreach ($this->_references as $key => $relation) {
$a[$key] = $relation->toArray($deep);
}
}
return array_merge($a, $this->_values); 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