kept getting FROM class undefined. and also Error: Invalid PathExpression. 
Must be a StateFieldPathExpression

seems that i had to add IDENTITY before ea.getme and also count is a 
reserved work i guess. changing it to 'num' solved the FROM class error. 

On Tuesday, April 25, 2017 at 11:58:47 AM UTC+1, Christophe COEVOET wrote:
>
> What you can do is this:
>
> ->select('ea.getme AS id', 'count(ea) AS count')
>
> This will then return you such structure:
>
> array(
>   0 => array('id' => 4, 'count' => 14),
>   1 => array('id' => 5, 'count' => 6),
> )
>
> If you remove the aliases in the selection part, keys will be 1 and 2 in 
> the array instead of 'id' and 'count'.
>
> If you want to get counts indexed by ids, this requires a transformation 
> of the result after that, but it is easy to do:
>
> $indexedCounts = array_column($results, 'count', 'id');
>
> -- 
> Christophe | Stof
>
>
> Le 25/04/2017 à 12:19, Andrew Davey a écrit :
>
> Hi guys,  
>
> I've got the following query uisng the createQueryBuilder
>
> $this->createQueryBuilder('ea')
>
>     ->select('distinct ea.getme')    ->where('ea.criteria1 = :criteria1')    
> ->andWhere('ea.criteria2 = :criteria2')    ->setParameter('criteria1', 
> 'somethine')    ->setParameter('criteria2', 'a value')    
> ->groupBy('ea.getme')    ->getQuery()    ->getArrayResult();
>
>
> this currently returns an array that looks something like this
>
> array(
>   0 => array( 1 => 4), 
>   1  => array( 1 => 5)
> )
>
> So far it just returns the distinct ids, this is ok. But what i would like 
> to do is also return the count of number of items for that unique field. i 
> dont know how to add it. but the end result i want to see is something like:
>
> array(
>   0 => array(4 => 14),
>   1 => array(5 => 6)
> )
>
> where 6 and 14 are the counts. 
>
> additionally, how can i get the result to be
>
> array( 
>   4 => 14,
>   5 => 6
> )
>
> thanks in advance for any and all help
> -- 
> You received this message because you are subscribed to the Google Groups 
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at https://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to