From a343421ebb16aad9c090b838671d1751a5ba2bd9 Mon Sep 17 00:00:00 2001
From: Nikhil Dubbaka <info@technikh.com>
Date: Sat, 17 Jan 2015 14:04:04 -0500
Subject: [PATCH] Issue #1969208 by TechNikh,benjifisher: skipping access check
 for entity reference.

---
 core/modules/node/src/NodeGrantDatabaseStorage.php | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/core/modules/node/src/NodeGrantDatabaseStorage.php b/core/modules/node/src/NodeGrantDatabaseStorage.php
index 1c0c0f7..ab3cb52 100644
--- a/core/modules/node/src/NodeGrantDatabaseStorage.php
+++ b/core/modules/node/src/NodeGrantDatabaseStorage.php
@@ -175,7 +175,16 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account
         // Now handle entities.
         $subquery->where("$nalias.$field = na.nid");
 
-        $query->exists($subquery);
+        // If it's a left join to entity table and entity does not exist (i.e.
+        // entity_id is null) then skip access check.
+        if ($tableinfo['join type'] == 'LEFT') {
+          $subquery_cond = db_or();
+          $subquery_cond->exists($subquery);
+          $subquery_cond->isNull("$nalias.$field");
+          $query->condition($subquery_cond);
+        } else {
+          $query->exists($subquery);
+        }
       }
     }
   }
-- 
1.8.3.4 (Apple Git-47)

