php - multiple select with inner join -


i try translate simple sql request doctrine no success:

select `groups`.`departure`, count(`group_users`.`group_id`) 'teamlength' `groups` inner join `group_users` `groups`.`id` = `group_users`.`group_id` , departure between '2017-03-01' , '2017-03-31' 

currently, code looks like:

public function finddatesbetween(\appbundle\entity\itinerary $itinerary, \datetime $firstdate, \datetime $lastdate) {   $q = $this->createquerybuilder('g')     ->select('g', 'count(gu.group) teamlength')     ->innerjoin('appbundle:groupuser', 'gu', join::with, 'g.id = gu.group')     ->andwhere('g.itinerary = :itineraryid')       ->setparameter('itineraryid', $itinerary->getid())     ->andwhere('g.departure between :firstdate , :lastdate')     ->setparameter('firstdate', $firstdate->format('y-m-d'))     ->setparameter('lastdate', $lastdate->format('y-m-d'));    return ($q->getquery()->getresult()); } 

if change select() : ->select('g'), works. need count(gu.group).

with actual code, have exception when try use departure: call member function getdeparture() on array

how can fix ? thank you.

you want aggregate result query, means result associative array , not array of entities instances. try data getarrayresult method , access data accordingly.

you can {{ dump(data) }} on twig view see structure of result.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -