We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33210
    • 4 Posts
    Hi there,

    can someone tell me, if/how it’s possible to select columns dynamically and using them as a sort column?
    Or if there is a different/better way to do something like this.

    I tried

    $c = $xpdo->newQuery('Post');
    $c->select(array(
      '*',
      '(SELECT AVG(`rating`)
         FROM `comments`
         WHERE `post` = `posts`.`id`
       ) AS `avg_rating`'
    ));
    


    And strangely get the correct number, of entries, when using:

    $xpdo->getCount('Post', $c);
    


    but:

    $xpdo->getCollection('Post', $c);
    


    has no entries?!


    And even more strange (at least for me):
    If, for some reason, the subquery only results in NULL values (error in the join)) ’getCollection’ will return all posts.



    Best regards and thanks a lot!