code: public function generate()
      {
          //$this->relatedObject->setParentModel($this->modelField->baseModel);
          if ($this->relationSettings) {
              $this->model->setParentModel($this->modelField->baseModel);
              // we are matching with an existing document
              $relationSettings = $this->relationSettings;
              if ($relationSettings === true) {
                  $relationSettings = ['template' => 'simple'];
              }
              if (!is_array($relationSettings)) {
                  $relationSettings = [];
              }
              if (!isset($relationSettings['template'])) {
                  $relationSettings['template'] = 'hierarchy';
              }
  
              return $this->generateRelationField($relationSettings);
          } elseif ($this->inlineRelation) {
              //$this->model->setParentModel($this->modelField->baseModel, false);
              $this->model->setParentModel($this->relatedObject);
              // we are matching with an existing document
              return $this->generateRelationField(['template' => 'fields']);
          } elseif (!empty($this->relatedObject)) {
              $this->model->setParentModel($this->relatedObject);
              $formSegment = $this->relatedObject->objectType->getFormSegment($this->relatedObject, ['relationField' => $this->modelField]);
              $formSegment->owner = $this->owner;
  
              return $formSegment->generate();
          } else {
              return;
          }
      }
docs: [[@doctodo method_description:generate]].
  
  @return unknown