在上面的例子中,如果我们要查询某个用户的所有文章并按照文章 aid 降序排列:
$article_list = $Dao->where('uid = 1')->order('aid DESC')->select();
这时候会得不到查询结果,打印出实际的 SQL 语句:
SELECT article.aid AS aid,article.title AS title,article.content AS content,article.uid AS uid, user.username AS username FROM test_article article JOIN test_user user ON article.uid=user.uid WHERE uid = 1 ORDER BY article.aid DESC
原因在于 article 和 user 表都包含了 uid 字段,这里可以使用上文提到的指定字段别名的方式来解决,一个更为简捷的办法是直接在条件里指定表名:
$article_list = $Dao->where('article.uid = 1')->order('aid DESC')->select();