diff --git a/modules/node/node.module b/modules/node/node.module
index 9e20234..2b94a29 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1002,6 +1002,8 @@ function node_validate($node, $form, &$form_state) {
  * Prepare node for saving by populating author and creation date.
  */
 function node_submit($node) {
+  global $user;
+
   // A user might assign the node author by entering a user name in the node
   // form, which we then need to translate to a user ID.
   if (isset($node->name)) {
@@ -3307,7 +3309,15 @@ function _node_query_node_access_alter($query, $type) {
         $field = 'entity_id';
       }
       $subquery->where("$nalias.$field = na.nid");
-      $query->exists($subquery);
+      
+      // Attach the subquery to entity conditions for entities or to the query
+      // itself for nodes
+      if($type == 'entity') {
+        $entity_conditions->exists($subquery);
+      } else {
+        $query->exists($subquery);
+      }
+      
     }
   }
 
