Martynas Tumas
Martynas Tumas

Reputation: 256

querybuilder select sums and joined entity

I'm trying to select sums and full joined entity

$qb = $this->createQueryBuilder('trl')
        ->select('sum(trl.billable_amount) as billable_amount,
          sum(trl.billable_duration) as billable_duration, 
          r as resource')
        ->join('trl.time_report', 'tr')
        ->join('trl.contact', 'c')
        ->leftJoin('c.resource', 'r')
        ->where('tr.id = :id')
        ->setParameter('id', $timeReportId)
        ->groupBy('r.id')
        ->having('billable_amount > 0');

error I get: [Semantical Error] line 0, col -1 near 'SELECT sum(trl.billable_amount)': Error: Cannot select entity through identification variables without choosing at least one root entity alias.

it works fine without "r as resource". Is it possible to join like this or should I get only resource id and get the entity with second query?

Upvotes: 0

Views: 792

Answers (1)

habibun
habibun

Reputation: 1630

select root entity alias too, try this

$qb = $this->createQueryBuilder('trl')
    ->select('trl, sum(trl.billable_amount) as billable_amount,
      sum(trl.billable_duration) as billable_duration, 
      r as resource')

Upvotes: 0

Related Questions