looking for good practices here =)
Basically, I have one Entity that is related to Elems with the ManyToOne relation.
Suppose I want to select only some elements from my entity.
I can do
class Entity {
public function getSpecificElems(){
forEach($this->elems as $elem){
if($someCondition){ $result[]=$elem;}
}
return $result;
}
But it can mean large data samples when there are many elements associated with my Entity. Another way:
$em->getRepository("AppBundle:Repository")->getSpecificElems($entity);
Where getSpecificElemsdoes the DQL query.
I have a problem: the first solution is more intuitive for me, because it is OOP. The second is faster to complete, but it seems bad to me.
Is there a way to mix both of 1) and 2) to get $entity->getSpecificElems(), in order to return the list, I want to execute a good SQL query?
Greetings