Question

I am kind of annoyed at Doctrine for returning primary keys in each and every query even though I don't want it to. Is there anyway to stop this ? coz I don't really want those damn primary keys along with my doctrine query results.

A query for instance that I have is:

$getAllDatesForUserQuery = $this->createQuery('s')
    ->select('s.datename')
    ->where('s.userid = ?',3)
    ->setHydrationMode(Doctrine::HYDRATE_ARRAY) ;

In this situation, it retrieves all the datenames as it should, but also happily returns the primary key column value. I DON"T WANT IT.

Is it me? or is it Doctrine ?

Was it helpful?

Solution

In a case like this where you want a simple array and only have a single field being selected, the answer is the Single Scalar Hydration mode. Use it like this:

$q = $this->createQuery('s')
->select('s.datename')
->where('s.userid = ?',3)
->setHydrationMode(Doctrine::HYDRATE_SINGLE_SCALAR);

You should find that the query will return a simple one-dimensional array containing only the value(s) you wanted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top