Doctrine žazení dle poslední historie
- breeta
- Člen | 68
Zdravím, mám tento dotaz s kterým si vytáhnu poslední id historie testů, th = historie testu, lze rovnou vytáhnout i hodnoty historie?
public function countTestTheme($theme, $user)
{
return $this->createQueryBuilder('th')
->leftJoin('th.videoTest', 'vt')
->leftJoin('vt.video', 'v')
->andWhere('v.theme = :theme') ->setParameter('theme', $theme)
->andWhere('th.user = :user')->setParameter('user', $user)
->select('max(th.id) AS maxId')
->groupBy('vt.id')
->getQuery()
->getResult();
;
}
- breeta
- Člen | 68
Když hodím hvězdičku tak to hodí error ale ikdyž dám th.id
->select(‚max(th.id) AS maxId, th.id‘)
Tak mi to pak vrací úplně jíné id, takže i ostatní hodnoty …
array:2 [▼
0 => array:2 [▼
"maxId" => "69"
"id" => 62
]
1 => array:2 [▼
"maxId" => "65"
"id" => 63
]
]
Phalanx napsal(a):
Proč ne –
->select('max(th.id) AS maxId, th.*')
Výsledek bude:
maxId, th.id, th.jiny_sloupec, …
maxId, th.id, th.jiny_sloupec, …
maxId, th.id, th.jiny_sloupec, …(nezapomeň si tam případně hodit limit)