code: public function setRelatedObjects($relatedObjects)
      {
          foreach ($relatedObjects as $modelName => $objects) {
              if (!isset($this->_relatedObjects[$modelName])) {
                  $this->_relatedObjects[$modelName] = [];
              }
              foreach ($objects as $tabId => $objectAttributes) {
                  if (!isset($objectAttributes['_moduleHandler'])) {
                      continue;
                  }
                  list($relationship, $role) = $this->owner->objectType->getRelationship($objectAttributes['_moduleHandler']);
                  $relatedHandler = $this->owner->objectType->getRelatedType($objectAttributes['_moduleHandler']);
                  if (!$relatedHandler) {
                      continue;
                  }
                  $objectAttributes = array_merge([
                      'companionObject' => $this->owner,
                      'companionRelationship' => $relationship,
                      'companionRole' => $role,
                      ], $objectAttributes);
                  $object = $relatedHandler->getModel(null, $objectAttributes);
                  $object->tabularId = $objectAttributes['_moduleHandler'];
                  if ((!$object
                      || $object->isEmptyObject())
                      && !($relationship->required)
                  ) {
                      continue;
                  }
  
                  $object->companionObject = $object->indirectObject = $this->owner;
                  $object->companionRelationship = $relationship;
                  $object->companionRole = $role;
                  $this->_relatedObjects[$modelName][$tabId] = $object;
                  $this->_relatedObjectsFlat[] = $object;
              }
          }
      }
docs: Set related objects.
  
  @param [[@doctodo param_type:relatedObjects]] $relatedObjects [[@doctodo param_description:relatedObjects]]