From 1ce02d8faff12a2edfbbb9847c404271bfe46a82 Mon Sep 17 00:00:00 2001
From: Yousef Bajawi <jose@josebcdev.com>
Date: Mon, 24 Oct 2016 16:04:31 +0300
Subject: [PATCH] Issue 2821631 by josebc: moved queue condition to the join

---
 .../views/relationship/EntityQueueRelationship.php     | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/Plugin/views/relationship/EntityQueueRelationship.php b/src/Plugin/views/relationship/EntityQueueRelationship.php
index 4463e6a..cb240c1 100644
--- a/src/Plugin/views/relationship/EntityQueueRelationship.php
+++ b/src/Plugin/views/relationship/EntityQueueRelationship.php
@@ -109,25 +109,21 @@ class EntityQueueRelationship extends EntityReverse implements CacheableDependen
    * {@inheritdoc}
    */
   public function query() {
-    parent::query();
-
-    // Add a 'where' condition if needed.
+    // Add a condition to the join in case limit to selection is set.
     if (!empty($this->definition['extra'])) {
       $bundles = [];
-
-      // Future-proofing: support any number of selected bundles.
       foreach ($this->definition['extra'] as $extra) {
         if ($extra['field'] == 'bundle') {
           $bundles[] = $extra['value'];
         }
       }
-
-      // Only add the 'where' condition if $bundles isn't empty.
-      if (!empty($bundles)) {
-        $op = count($bundles) > 1 ? 'IN' : '=';
-        $this->query->addWhere(0, $this->alias . '.name', $bundles, $op);
-      }
+      $this->definition['join_extra'][] = [
+        'field' => 'bundle',
+        'operator' => 'IN',
+        'value' => [$bundles],
+      ];
     }
+    parent::query();
   }
 
 }
-- 
1.9.1

