I have Entity 1: Upload , it has a oneToMany relationship to comments
i have a custom respository for Upload, and i want to find the most commented uploads.
so when i do
/**
* @param $sortBy String
* @param $limit Int
*/
public function getWeekTopUploads($sortBy,$limit){
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->add('select', 'u')
->add('from', 'TrackerMembersBundle:Upload u')
// ->where('u.created')
->orderBy('u.comments', 'DESC')
->setMaxResults( $limit );
$query = $qb->getQuery();
$result = $query->getResult();
return $result;
}
i get the error:
[Semantical Error] line 0, col 55 near 'comments DES': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.
500 Internal Server Error - QueryException
it seems not to want to accept ordering by number of comments, how can i solve this or what would be the proper re-write for the query builder?
You must pass ‘u’ as param to your createQueryBuilder() function, and declare your getWeekTopUploads() function in your UploadRepository: