在hook_views_query_alter()中添加一个JOIN语句 [英] Adding a JOIN statement in hook_views_query_alter()

查看:233
本文介绍了在hook_views_query_alter()中添加一个JOIN语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改视图生成的查询,以便我可以使用高度自定义的过滤器。由于这个问题,我已经执行了add_where()函数: Drupal中的OR运算符查看过滤器

I need to modify a query Views generates so that I can use highly custom filters. I have implemented the add_where() function with some ORs thanks to this question: OR operator in Drupal View Filters

但这只解决了我的一部分问题。有一些我无法过滤的字段,因为我需要在查询中加上额外的JOIN。

However this only solves a part of my problem. There are some fields that I cannot filter on because I need to have extra JOINs in my query.

有没有一些沿着

$view->query->add_where()

可以插入JOIN语句?

that can insert JOIN statements?

推荐答案

嗯,有 $ view - > query-> add_table() $ view-> query-> add_relationship()(在view_query类中,包括/ query.inc'),但是它们的用法,关系和前提条件从代码中是不明显的(至少对我来说)。

Well, there is $view->query->add_table() and $view->query->add_relationship() (in the views_query class in 'includes/query.inc'), but their usage, relation and preconditions are not obvious from the code (at least not for me).

也许你可以添加关系通过Views UI确保您需要的表格加入。

Maybe you could add the relationships via the Views UI to ensure that your needed tables get joined in.

(注意:更好的主意出现了:/

(Note: Comment turned to answer, as no better idea showed up :/

这篇关于在hook_views_query_alter()中添加一个JOIN语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆