简体   繁体   English

Drupal视图中的节点关系

[英]Node relations in Drupal Views

I'm struggling a little bit with a View that gets data from a node that uses two node reference fields, that points to the same type of content. 我在一个View中苦苦挣扎,该View从使用两个节点引用字段的节点获取数据,该节点指向相同类型的内容。 From my path I'm getting one string as the argument, let's call it $fruit . 从我的路径中,我得到一个字符串作为参数,我们将其称为$fruit

The query I would make if I was writing the query myself would be something like SELECT * FROM recipe WHERE (fruit_1=$fruit OR fruit_2=$fruit) . 如果我自己编写查询,我将执行的查询将类似于SELECT * FROM recipe WHERE (fruit_1=$fruit OR fruit_2=$fruit) My problem is that I don't get how to do this in a Drupal View. 我的问题是我没有在Drupal视图中做到这一点。 Any suggestions? 有什么建议么?

UPDATE: I finally solved what I've been trying to do. 更新:我终于解决了我一直想做的事情。 The solution for me was to use Panels together with a View using Views Or arguments, and setting both of the arguments values to the same using the first Panels argument. 对我来说,解决方案是将Panels与使用Views Or参数的View一起使用,并使用第一个Panels参数将两个参数值设置为相同。 Not sure if I'm explaining either my problem or my solution properly, but if anyone would need a closer explanation, feel free to ask. 不知道我是在正确解释我的问题还是在解决方案,但是如果有人需要更详细的解释,请随时提问。

Views Or module addon: http://drupal.org/project/views_or 视图或模块插件: http : //drupal.org/project/views_or

It really ought to be included with Views by default because it is so powerful. 默认情况下,它确实应该包含在Views中,因为它是如此强大。

The 'begin alternatives' option essentially places a '(' in your query. The 'next alternative' option essentially places the ' OR ' in your query. The 'end alternatives' option essentially places a ')' in your query. 'begin Alternatives'选项本质上在查询中放置了'('。'next Alternative'选项本质上将在查询中放置'OR'。'end Alternatives'选项本质上将在查询中放置')'。

Views filters are setup as ' AND ' between each field, this adds that ' OR ' capability. 视图过滤器在每个字段之间设置为“与”,这增加了“或”功能。 So using your example your filters would be something like: 因此,使用您的示例,您的过滤器将类似于:

Content Type = Recipe
Begin Alternatives
Node Title = fruit_1
Next Alternative
Node Title = fruit_2
End Alternatives

Note that you can have several Or options by using more 'next alternative' filters, each places an ' OR ' between the other filters. 请注意,通过使用更多的“下一个替代”过滤器,您可以拥有多个“或”选项,每个过滤器在其他过滤器之间放置一个“或”。 If it's still confusing, check the query preview in your views pane after each change. 如果仍然令人困惑,请在每次更改后在视图窗格中检查查询预览。

I don't think there's a way to do the ... OR ... part of your query in the Views UI. 我认为没有方法可以在Views UI中执行查询的... OR ...部分。 However, you can make your own module and use the Views UI to generate the first part of the query, then use hook_views_query_alter in your module to just append WHERE (fruit_1=$fruit OR fruit_2=$fruit) to the end of the query. 但是,您可以创建自己的模块,并使用Views UI生成查询的第一部分,然后在模块中使用hook_views_query_alterWHERE (fruit_1=$fruit OR fruit_2=$fruit)追加到查询末尾。

More info on hook_views_query_alter here and here . 此处此处有关hook_views_query_alter更多信息。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM