1
First, we know that depending on the number of columns in a query, you can increase the response time.
In Doctrine I call the following repository, which has a relationship and brings all the columns of both entities.
public function index()
{
$this->alunos = $this->model->getRepository()->findAll();
}
But thinking about the statement I gave earlier, the return of this repository is more time consuming than if it were an entity without relationship?
And another doubt?
Can I select the columns I want to return from this repository? For example, the above repository returns:
id (entidade aluno)
nome (entidade aluno)
id_turma (entidade turma)
But I would like to return only the name of the student. Type like this:
public function index()
{
$this->alunos = $this->model->getRepository()->findAll("nome");
// ou assim pra pegar mais de um campo
$this->alunos2 = $this->model->getRepository()->findAll("nome, dtNascimento");
}
I know it doesn’t work that way, just to illustrate.
Opa, +Rudi Rocha, thanks for the answer. So, to confirm, there is no way to select these fields by the repository right? Type
$this->alunos = $this->model->getRepository()->findAll("nome");
iai would bring only the name field. PS: I know q doesn’t work like this, it was just to exemplify.– LeoFelipe
@Leofelipe The findAll() method does not accept columna names as arguments. I think you should see the documentation at: http://doctrine-orm.readthedocs.org/en/latest/tutorials/getting-started.html
– Rudi Rocha