作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试加入每个节点的五星级评级,以便我可以按评级对它们进行排序。问题是我正在查询的 Fivestar 值作为每个节点的多行存储在 Votingapi_cache 中(投票数和平均评分),因此我想执行以下操作:
...
LEFT JOIN votingapi_cache fivestar
ON fivestar.entity_id = node.nid
AND fivestar.function = 'average'
我尝试了以下代码,但问题是对“Fivestar.function = 'average'”的检查添加到了 where 子句中,从而消除了所有没有投票的节点。
$query->leftjoin('votingapi_cache', 'fivestar', 'fivestar.entity_id = n.nid');
$query->condition('fivestar.function', 'average', '=');
$query->addField('fivestar', 'value', 'average_rating');
<小时/>
好吧,我第一次尝试这个时肯定做错了什么,但解决方案如下:
$query->leftjoin('votingapi_cache', 'fivestar', "fivestar.entity_id = n.nid AND fivestar.function = 'average'");
最佳答案
好吧,我第一次尝试这个时肯定做错了什么,但解决方案如下:
$query->leftjoin('votingapi_cache', 'fivestar', "fivestar.entity_id = n.nid AND fivestar.function = 'average'");
关于drupal-7 - 如何将多个条件应用于 db_select 上的 leftjoin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8695993/
我是一名优秀的程序员,十分优秀!