APIv4 - Ensure getFields always returns table_name and column_name
[civicrm-core.git] / Civi / Api4 / Service / Spec / RequestSpec.php
index dbf460a3ba71bd2888ce0d435b0a5608cdded360..d9e2b5bf135c1b412ec3ee3a9e2e1cd93773e281 100644 (file)
@@ -19,6 +19,8 @@
 
 namespace Civi\Api4\Service\Spec;
 
+use Civi\Api4\Utils\CoreUtil;
+
 class RequestSpec {
 
   /**
@@ -31,6 +33,11 @@ class RequestSpec {
    */
   protected $action;
 
+  /**
+   * @var string
+   */
+  protected $entityTableName;
+
   /**
    * @var FieldSpec[]
    */
@@ -43,9 +50,16 @@ class RequestSpec {
   public function __construct($entity, $action) {
     $this->entity = $entity;
     $this->action = $action;
+    $this->entityTableName = CoreUtil::getTableName($entity);
   }
 
   public function addFieldSpec(FieldSpec $field) {
+    if (!$field->getEntity()) {
+      $field->setEntity($this->entity);
+    }
+    if (!$field->getTableName()) {
+      $field->setTableName($this->entityTableName);
+    }
     $this->fields[] = $field;
   }