1
0
mirror of synced 2025-01-18 06:21:40 +03:00

toArray now can return also the record relations

This commit is contained in:
jackbravo 2007-08-28 16:45:22 +00:00
parent 11bae7774d
commit bd61271579
2 changed files with 25 additions and 3 deletions

View File

@ -580,9 +580,25 @@ 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)
{ {
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() public function getDeleteDiff()
{ {

View File

@ -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
$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);
} }
/** /**