I am using Symfony 2 PR12 with Doctrine 2 and MySQL. I have a database that stores articles and presentations of these articles:
class Article {
protected $id;
protected $views;
}
class ArticleView {
protected $id;
protected $viewDate;
protected $article;
}
I want to get, for example, the 20 most recently viewed articles. My first thought would be this:
$qb = <instance of Doctrine\ORM\QueryBuilder>;
$qb->select('a')
->from('Article', 'a')
->join('a.views', 'v')
->orderBy('v.viewDate', 'DESC')
->groupBy('a.id')
->setMaxResults(20)
;
However, if there is more than one view associated with the article, the order-by / group-by combination gives unpredictable results for ordering.
MySQL, , http://www.artfulsoftware.com/infotree/mysqlquerytree.php ( β ). , DQL, , , .
, ?