Majdi Taleb
Majdi Taleb

Reputation: 761

doctrine2 select specific columns

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?

Upvotes: 0

Views: 110

Answers (1)

Fireeyes
Fireeyes

Reputation: 108

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.

Upvotes: 1

Related Questions