code: public function beforeSave($event)
      {
          foreach ($this->_relations as $key => $relation) {
              unset($relation['_moduleHandler']);
              if (!empty($this->companionObject)) {
                  if ($this->companionRole === 'child') {
                      $relation['parent_object_id'] = $this->companionObject->primaryKey;
                  } else {
                      $relation['child_object_id'] = $this->companionObject->primaryKey;
                  }
              }
              if (empty($relation['child_object_id']) && empty($relation['parent_object_id'])) {
                  if (!empty($this->_relations) && (!$this->companionObject || empty($this->companionObject->primaryKey))) {
                      $event->isValid = false;
                      $this->owner->addError('_', 'Saving relations with no companion object! ' . get_class($this->owner));
  
                      return false;
                  }
              }
              $this->owner->registerRelationModel($relation, $key);
          }
      }
docs: [[@doctodo method_description:beforeSave]].
  
  @param [[@doctodo param_type:event]] $event [[@doctodo param_description:event]]
  
  @return [[@doctodo return_type:beforeSave]] [[@doctodo return_description:beforeSave]]