English 中文(简体)
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. From my path I m getting one string as the argument, let s call it $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). My problem is that I don t get how to do this in a Drupal View. 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. 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

It really ought to be included with Views by default because it is so powerful.

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.

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. 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.

More info on hook_views_query_alter here and here. Good luck.





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签