Query to order on different tables doesn’t work

I have some entities/tables:

-Content
-ContentCategory
-Editor who can be premium and who create Contents
-Star (gold contents)like that: Star(IdContent, IdCategoryContent, IdEditor), because there can be only one star for each category for each editor.

I want a query to get every Contents but ordered to shows only one content from each editor at first (star content of premium plan editors) and then every other contents.

What I tried, thanks for any help :

$query = $this->getEntityManager()->createQueryBuilder()
    ->select('c')
    ->from('ContentBundle:Content', 'c')
    ->leftJoin('c.user', 'user')
    ->leftJoin('user.editoreditor', 'editor')
    ->leftJoin(
        'loicContentBundleEntityStar',
        'star',
        DoctrineORMQueryExprJoin::WITH,
        'c.idcontent = star.idContent'
    )
    ->orderBy('editor.plan', 'DESC')
    ->addOrderBy('star.idContent', 'DESC')
    ->addOrderBy('c.creationDate', 'DESC');

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *