gpt4 book ai didi

drupal-7 - 如何将多个条件应用于 db_select 上的 leftjoin?

转载 作者:行者123 更新时间:2023-12-02 19:17:25 25 4
gpt4 key购买 nike

我正在尝试加入每个节点的五星级评级,以便我可以按评级对它们进行排序。问题是我正在查询的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com