original_string: public function findRelatedModel($modelName, $field, $id = NULL) {
      $relatedModel = $this->getInstance($modelName);
  
      if ($this->isNew() && $id === NULL) {
        throw new \Exception('No id for related');
      }
  
      if ($id === NULL) {
        $id = $this->getField($field);
      }
  
      $result = $relatedModel->findById($id);
  
      return $result;
    }
code: public function findRelatedModel($modelName, $field, $id = NULL) {
      $relatedModel = $this->getInstance($modelName);
  
      if ($this->isNew() && $id === NULL) {
        throw new \Exception('No id for related');
      }
  
      if ($id === NULL) {
        $id = $this->getField($field);
      }
  
      $result = $relatedModel->findById($id);
  
      return $result;
    }
code_tokens: public function findRelatedModel ( $ modelName , $ field , $ id = NULL ) { $ relatedModel = $ this -> getInstance ( $ modelName ) ; if ( $ this -> isNew ( ) && $ id === NULL ) { throw new \ Exception ( 'No id for related' ) ; } if ( $ id === NULL ) { $ id = $ this -> getField ( $ field ) ; } $ result = $ relatedModel -> findById ( $ id ) ; return $ result ; }
docstring: Finds a related model instance by the given field name and the id value.
  
  Use it in a 1 to N relation, with an object instance of the N side to the get 1 related model.
  
  @param $modelName : The related model name.
  @param $field : The field that must be used to relate.
  @param $id : Optional, the ID the related model, if is not given the value of the field in the executor object will be used.
  
  @throws \Exception : if a invalid model is given.
  
  @return Related Instance.
docstring_tokens: Finds a related model instance by the given field name and the id value .