Merge pull request #11635 from civicrm/4.7.30-rc
[civicrm-core.git] / Civi / API / SelectQuery.php
index 7e047bd182c1a5a1fc35629dd935efa977302b73..b052ec41898880540004e8ce871ad9c08b20e118 100644 (file)
@@ -467,8 +467,10 @@ abstract class SelectQuery {
       }
     }
 
-    // Always select the ID.
-    $this->selectFields[self::MAIN_TABLE_ALIAS . ".id"] = "id";
+    // Always select the ID if the table has one.
+    if (array_key_exists('id', $this->apiFieldSpec)) {
+      $this->selectFields[self::MAIN_TABLE_ALIAS . ".id"] = "id";
+    }
 
     // core return fields
     foreach ($return as $fieldName) {