2

I looked up this one before posting: Views filter criteria multiple content types (Drupal 7)

And even though the problem is the same, the solutions provided do not seem to work.

I have Content Types A and B. B has a boolean field.

I need to filter and display all As and Bs if boolean is true.

My filter setup looks like this:

Content : Published AND Content Type : A

OR

Content : Published AND Content Type : B AND Boolean Field : True

The Query that gets produced is the following:

SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created
FROM `node`
INNER JOIN `field_data_field_boolean` ON node.nid = field_data_field_boolean.entity_id 
  AND (field_data_field_boolean.entity_type = 'node' 
  AND field_data_field_boolean.deleted = '0')
WHERE (( (node.status = '1') 
  AND (node.type IN  ('poll')) )OR( (node.status = '1') AND (node.type IN  ('webform')) 
  AND (field_data_field_boolean.field_boolean_value = '1') ))
ORDER BY node_created DESC

The problem is that Inner Join that gets produced instead of a Left Join for instance.

Which setup would allow me to perform the required filtering?

EDIT: Seems it's a know bug. Related links: http://drupal.org/node/1766338 Changing an inner join to a left join in views 3.3?

4
  • Is there any link between Content Type A & B? In other words, does A refer to B in any way?
    – Q10
    Jan 9, 2013 at 7:28
  • nope, none at all.
    – user5005
    Jan 9, 2013 at 10:30
  • 2
    I think this is a bug reported at drupal.org/node/1766338
    – cherouvim
    Jan 9, 2013 at 10:37
  • Answering this as a bug/can't be done. For more information visit drupal.org/node/1766338
    – user5005
    Feb 13, 2013 at 16:40

2 Answers 2

7

Although this post is quite old, it appears it's still an issue going up to Views 7.x-3.7. Referring to the post already mentioned here and specifically comment 36 on that page, I found my working solution.

I had two content types that I wanted to show the title from: an Event and a Blog, however I only wanted the blog posts which had a Boolean field returning as true. Below is a screenshot of what my grouping filters look like but the trick is, on the Boolean filter, make sure you select the 'Reduce duplicates' check-box. Once I did that, I got the results I was expecting.

Hope that helps.

enter image description here

2
  • Thanks! That's what I was missing. Checking the Reduce duplicates on each field, changed the query from INNER JOIN to LEFT JOIN which made all the content appear
    – Piyin
    Aug 30, 2017 at 14:25
  • My god! I've been using Drupal for 8 years or longer and never have I known about this feature until now! Jun 1, 2018 at 15:57
0

I often struggle with views doing what I want. My solution is to override the automatically generated query with my own.

Below I give you an example of a list of members of the currently viewed group with the specific group role:

function mymodule_views_pre_execute(&$view) {
    if($view->name=="og_members") {
        $nid = arg(1);
        $gid = mymodule_get_gid_from_nid($nid);
        $query = db_select('users');
        $query->join('og_users_roles', 'roles', 'users.uid = roles.uid'); 
        $query->addfield('users','name','users_name');
        $query->addfield('users','uid','uid');
        $query->condition('roles.rid', VISITOR_ROLE_ID,'!=');
        $query->condition('roles.gid', $gid,'=');
        $view->build_info['query'] = $query;
    }
}

A thing to not here is that returned field should match the fields that the view will expect.

2
  • that kinda defeats the whole purpose though, doesn't it? :)
    – user5005
    Jan 10, 2013 at 8:34
  • You still get the very powerful engine for displaying the results. Access control and other goodies that views give you. Using gui you will never be able to click-out the more complicated queries.
    – Pawel G
    Jan 10, 2013 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.