looking for good practices here =)
Basically, I got one Entity, which is linked to Elems with a ManyToOne Relationship.
Lets say I want to select only some Elems from my Entity.
I can do
class Entity {
/* some vars here */
public function getSpecificElems(){
forEach($this->elems as $elem){
/* do stuff here */
if($someCondition){ $result[]=$elem;}
}
return $result;
}
But that could imply large data fetching when there are many elems linked to my Entity. The other way would be
$em->getRepository("AppBundle:Repository")->getSpecificElems($entity);
Where getSpecificElems executes a DQL query.
I have got a problem here : the first solution is more intuitive to me because it is OOP. The second one is faster to execute, but seems bad to me.
Is there a way to mix both of 1) and 2) in order to get $entity->getSpecificElems() to return the list I want executing the good SQL query ?
Cheers,