4

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

2
  • Did you try Query::HYDRATE_OBJECT?
    – zim32
    May 30, 2011 at 20:37
  • $query = $em->createQuery('SELECT u FROM CmsUser u'); $users = $query->getResult(Query::HYDRATE_OBJECT);
    – zim32
    May 30, 2011 at 20:37

1 Answer 1

0

Change your results method

return $q->getArrayResult();

http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#array-hydration

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.