toArray now can return also the record relations
This commit is contained in:
parent
11bae7774d
commit
bd61271579
@ -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);
|
||||
}
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user