0
votes

In mysql, we can return specific result like as:

select  name,lastName from users where id=1;

how use the same request in doctrine2? I khnow that we can use

$query=$this->_em->createQuery('select a.name, a.lastName from ...:Users a'); but i search some methods to user it without a.name

for examlpe

$query=$this->_em->createQuery('select name, lastName from ...:Users '); is correct?

it's possible to return just the name and the lastname from a table without the prefix a?

1

1 Answers

1
votes

If you want to select some specific fields from the database you need to use the partial keyword.

Taken from the doctrine partial object documentation your query should look like:

$query=$this->_em->createQuery('SELECT partial u.{name, lastName} from Users u');

This will return an array of partially loaded User objects.