drupal view2用于JOIN的views_query_alter
我正在尝试更改 drupal view-2 查询,基本上是想再添加一张表。我可以使用 hook_views_query_alter() 更改查询的 where 子句,但不知道如何再加入一张表。
function module_views_query_alter(&$view, &$query) {
if ($view->name == 'view1_name') {
$query->where[0]['args'][] = 'SOMETEXT';
$query->where[0]['clauses'][] = "QUERY";
}
if($view->name = 'view2_name'){
$query->table_queue['content_type_sold_product'];
$query->tables['content_type_sold_product'];
}
}
为什么我要这样做 - 如果关系选项卡在用于联接表的视图中可用,但在我的情况下,我要联接的表包含不是节点引用的字段,但字段名称及其值匹配与视图表表之一。
有谁知道如何在views_query_alter()中执行JOIN。
i'm trying to alter drupal view-2 query, basically want to add one more table. I'm able to alter the where clause of query using hook_views_query_alter() but don't know how to join one more table.
function module_views_query_alter(&$view, &$query) {
if ($view->name == 'view1_name') {
$query->where[0]['args'][] = 'SOMETEXT';
$query->where[0]['clauses'][] = "QUERY";
}
if($view->name = 'view2_name'){
$query->table_queue['content_type_sold_product'];
$query->tables['content_type_sold_product'];
}
}
Why do i want to do this - if relationship tab is available in view that is used to join the table, but in my case table which i want to join contains the field that is not a node-reference however field name and its value matches with one of the view table table.
Does anyone know how to perform JOIN in views_query_alter().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答自己的问题
幸运的是,我找到了这些链接
http://drupalmodules。 com/module/reverse-node-reference 模块通过节点引用字段的反向关系增强视图。
您可能还需要 http://drupal.org/project/noderelationships
Giving Answer to own question
fortunately i found these links
http://drupalmodules.com/module/reverse-node-reference module enhances views with reverse relationships for node reference fields.
you may also need http://drupal.org/project/noderelationships
似乎有两种不同的方法可以做到这一点,请参阅以下链接:
在hook_views_query_alter()中添加JOIN语句
添加表连接,其中,和views_query_alter()中的视图查询的Order By
Seems there are two different ways you can do this, see these links:
Adding a JOIN statement in hook_views_query_alter()
Add Table Join, Where, and Order By to Views Query in views_query_alter()