I'm trying to implement deep copy functionality using Doctrine 2, and I almost have it except for a method on one of my entities that attempts to strip out certain records from an association before returning the collection.
The problem is that when I call getRoofAreas() below, I get an array of Proxy objects, which my deep copy code doesn't like:
/**
* @OneToMany(targetEntity="\Entities\QuotingRoofAreas", mappedBy="customerId", cascade={"persist"})
* @OrderBy({"areaIndex" = "ASC"})
*/
private $roofAreas;
public function getRoofAreas() {
$em = \Zend_Registry::get('em');
$q = $em->createQuery("select ra from \Entities\QuotingRoofAreas ra where ra.dateDeleted IS NULL and ra.customerId = " . $this->getId());
return $q->getResult();
}
but if I were to change this to:
/**
* @OneToMany(targetEntity="\Entities\QuotingRoofAreas", mappedBy="customerId", cascade={"persist"})
* @OrderBy({"areaIndex" = "ASC"})
*/
private $roofAreas;
public function getRoofAreas() {
return $roofAreas;
}
then it would return a persistent collection which, when iterated through, would get me Entity objects, which is what I want. The latter approach doesn't strip out deleted roof areas, which is a must for my use case.
Is there a way to get the Entity object for a Proxy object?
Thanks in advance for any help anyone can provide
Change your results method
http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#array-hydration