public function counterpart()
    {
        if ($this->_counterpart) {
            return $this->_counterpart;
        }

        $to = $this->to();

        $from = $this->from();
        $relations = $to::definition()->relations();
        $result = [];

        foreach ($relations as $relation) {
            $rel = $to::definition()->relation($relation);
            if ($rel->to() === $this->from()) {
                $result[] = $rel;
            }
        }
        if (count($result) === 1) {
            return $this->_counterpart = reset($result);
        } elseif (count($result) > 1) {
            throw new ORMException("Ambiguous {$this->type()} counterpart relationship for `{$from}`. Apply the Single Table Inheritance pattern to get unique models.");
        }
        throw new ORMException("Missing {$this->type()} counterpart relationship for `{$from}`. Add one in the `{$to}` model.");
    }
public function counterpart()
    {
        if ($this->_counterpart) {
            return $this->_counterpart;
        }

        $to = $this->to();

        $from = $this->from();
        $relations = $to::definition()->relations();
        $result = [];

        foreach ($relations as $relation) {
            $rel = $to::definition()->relation($relation);
            if ($rel->to() === $this->from()) {
                $result[] = $rel;
            }
        }
        if (count($result) === 1) {
            return $this->_counterpart = reset($result);
        } elseif (count($result) > 1) {
            throw new ORMException("Ambiguous {$this->type()} counterpart relationship for `{$from}`. Apply the Single Table Inheritance pattern to get unique models.");
        }
        throw new ORMException("Missing {$this->type()} counterpart relationship for `{$from}`. Add one in the `{$to}` model.");
    }
public function counterpart ( ) { if ( $ this -> _counterpart ) { return $ this -> _counterpart ; } $ to = $ this -> to ( ) ; $ from = $ this -> from ( ) ; $ relations = $ to :: definition ( ) -> relations ( ) ; $ result = [ ] ; foreach ( $ relations as $ relation ) { $ rel = $ to :: definition ( ) -> relation ( $ relation ) ; if ( $ rel -> to ( ) === $ this -> from ( ) ) { $ result [ ] = $ rel ; } } if ( count ( $ result ) === 1 ) { return $ this -> _counterpart = reset ( $ result ) ; } elseif ( count ( $ result ) > 1 ) { throw new ORMException ( "Ambiguous {$this->type()} counterpart relationship for `{$from}`. Apply the Single Table Inheritance pattern to get unique models." ) ; } throw new ORMException ( "Missing {$this->type()} counterpart relationship for `{$from}`. Add one in the `{$to}` model." ) ; }
Returns the counterpart relation.

@return object
Returns the counterpart relation .