How to delete a Grant by GID Typically grants are deleted by $nid whenever new grants are added.  In fact this function is baked into node_access_write_grants() (when $delete = TRUE).

I have been using custom GID's to represent different users's Address IDs ($aid).  When a user edits his/her address I want all the old grants with that GID/AID to be deleted but leave the grants on the particular node to be untouched.
It would appear to me that Drupal 7 has no built in way to delete grants by GID, only by $node. Because of this I'm advocating doing a simple database query very similar to the query in node_access_write_grants().

Original:

 if ($delete) {
    $query = db_delete('node_access')
             -&gt;condition('nid', $node-&gt;nid);
    if ($realm) {
      $query-&gt;condition('realm', array($realm, 'all'), 'IN');
    }
    $query-&gt;execute();
 }


My code:

$query = db_delete('node_access')
         -&gt;condition('gid', $address-&gt;aid);
$query-&gt;execute();


Perhaps there's something to be said for using the 'realm' field to circumvent this issue.  However, this seems to work.  I'd love to know what the community thinks.