original_string: public function ref($ref1)
      {
          list($ref, $rest) = explode('/', $ref1, 2);
  
          if (!isset($this->_references[$ref])) {
              /** @type Field_Base $e */
              $e = $this->hasElement($ref);
              if ($e && $e->hasMethod('ref')) {
                  return $e->ref();
              } else {
                  throw $this->exception('Reference is not defined')
                      ->addMoreInfo('model', $this)
                      ->addMoreInfo('ref', $ref);
              }
          }
  
          $class = $this->_references[$ref];
          if (is_array($class)) { // hasMany
              if ($rest) {
                  throw $this->exception('Cannot traverse multiple references');
              }
              $m = $this->_ref(
                  $class[0],
                  $class[1] && $class[1] != UNDEFINED ? $class[1] : $this->table.'_id',
                  $class[2] && $class[2] != UNDEFINED ? $this[$class[2]] : $this->id
              );
          } else { // hasOne
              $id = $this->get($ref);
              /** @type Model $m */
              $m = $this->_ref(
                  $class,
                  null,
                  $id
              );
              if ($id) {
                  $this->hook('beforeRefLoad', array($m, $id));
                  $m->load($id);
              }
          }
          if ($rest) {
              $m = $m->ref($rest);
          }
  
          return $m;
      }
code: public function ref($ref1)
      {
          list($ref, $rest) = explode('/', $ref1, 2);
  
          if (!isset($this->_references[$ref])) {
              /** @type Field_Base $e */
              $e = $this->hasElement($ref);
              if ($e && $e->hasMethod('ref')) {
                  return $e->ref();
              } else {
                  throw $this->exception('Reference is not defined')
                      ->addMoreInfo('model', $this)
                      ->addMoreInfo('ref', $ref);
              }
          }
  
          $class = $this->_references[$ref];
          if (is_array($class)) { // hasMany
              if ($rest) {
                  throw $this->exception('Cannot traverse multiple references');
              }
              $m = $this->_ref(
                  $class[0],
                  $class[1] && $class[1] != UNDEFINED ? $class[1] : $this->table.'_id',
                  $class[2] && $class[2] != UNDEFINED ? $this[$class[2]] : $this->id
              );
          } else { // hasOne
              $id = $this->get($ref);
              /** @type Model $m */
              $m = $this->_ref(
                  $class,
                  null,
                  $id
              );
              if ($id) {
                  $this->hook('beforeRefLoad', array($m, $id));
                  $m->load($id);
              }
          }
          if ($rest) {
              $m = $m->ref($rest);
          }
  
          return $m;
      }
code_tokens: public function ref ( $ ref1 ) { list ( $ ref , $ rest ) = explode ( '/' , $ ref1 , 2 ) ; if ( ! isset ( $ this -> _references [ $ ref ] ) ) { /** @type Field_Base $e */ $ e = $ this -> hasElement ( $ ref ) ; if ( $ e && $ e -> hasMethod ( 'ref' ) ) { return $ e -> ref ( ) ; } else { throw $ this -> exception ( 'Reference is not defined' ) -> addMoreInfo ( 'model' , $ this ) -> addMoreInfo ( 'ref' , $ ref ) ; } } $ class = $ this -> _references [ $ ref ] ; if ( is_array ( $ class ) ) { // hasMany if ( $ rest ) { throw $ this -> exception ( 'Cannot traverse multiple references' ) ; } $ m = $ this -> _ref ( $ class [ 0 ] , $ class [ 1 ] && $ class [ 1 ] != UNDEFINED ? $ class [ 1 ] : $ this -> table . '_id' , $ class [ 2 ] && $ class [ 2 ] != UNDEFINED ? $ this [ $ class [ 2 ] ] : $ this -> id ) ; } else { // hasOne $ id = $ this -> get ( $ ref ) ; /** @type Model $m */ $ m = $ this -> _ref ( $ class , null , $ id ) ; if ( $ id ) { $ this -> hook ( 'beforeRefLoad' , array ( $ m , $ id ) ) ; $ m -> load ( $ id ) ; } } if ( $ rest ) { $ m = $ m -> ref ( $ rest ) ; } return $ m ; }
docstring: Traverses reference of relation.
  
  @param string $ref1
  
  @return Model
docstring_tokens: Traverses reference of relation .