R – Node relations in Drupal Views

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

Best Answer

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.

Related Topic