--- domain_adv.module.orig	2009-01-04 21:01:38.000000000 -0800
+++ domain_adv.module	2010-06-04 23:05:22.414510910 -0700
@@ -23,6 +23,20 @@
   switch ($primary_field) {
     case 'nid':
       $return = array();
+
+      // Don't alter the query if there are already domain_access conditions
+      // in the where clause (ie, coming from a view).
+      if (strpos($query, 'domain_access') && ($where_pos = strpos($query, 'WHERE'))) {
+        // The domain access table is already in the query and there is a where clause
+        $order_pos = strpos($query, 'ORDER BY');
+
+        if (($domain_pos = strpos($query, 'domain_access', $where_pos)) && ($domain_pos < $order_pos || $order_pos === FALSE)) {
+          // The domain access table is being referenced in the where clause
+          // Don't alter the query with additional domain_access restrictions
+          return $return;
+        }
+      }
+
       $return['join'] = 'LEFT JOIN {domain_access} da ON '. $primary_table .'.nid = da.nid';
       $return['where'] = '(da.realm = "domain_id" AND da.gid = '. $GLOBALS['_domain']['domain_id'] .')';
       if ($GLOBALS['_domain']['domain_id']) {
