Commit 65442c74 authored by guilhermeblanco's avatar guilhermeblanco

Added free( = false) support in Doctrine_Record and Doctrine_Collection (trunk)

parent a6a5192f
......@@ -912,6 +912,24 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return $this;
}
public function free($deep = false)
{
foreach ($this->getData() as $key => $record) {
if ( ! ($record instanceof Doctrine_Null)) {
$record->free($deep);
}
}
$this->data = array();
if ($this->reference) {
$this->reference->free($deep);
$this->reference = null;
}
}
/**
* getIterator
* @return object ArrayIterator
......
......@@ -1902,11 +1902,22 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function free()
{
if ($this->_state != self::STATE_LOCKED) {
$this->_mapper->detach($this);
$this->_mapper->removeRecord($this);
$this->_data = array();
$this->_id = array();
if ($deep) {
foreach ($this->_references as $name => $reference) {
if ( ! ($reference instanceof Doctrine_Null)) {
$reference->free($deep);
}
}
}
$this->_references = array();
}
}
}
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