Returns the counterpart relation.

@return object
548392
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.");
    }
1264192
public function getRelations()
    {
        $relations = $columns = [];

        foreach ($this->builder->fields() as $field) {
            $columns[] = $field->column();
        }

        foreach (array_flatten($columns) as $column) {
            if (str_contains($column, '.')) {
                list($relation) = explode('.', $column);

                if (method_exists($this->model, $relation) &&
                    $this->model->$relation() instanceof Relation
                ) {
                    $relations[] = $relation;
                }
            } elseif (method_exists($this->model, $column) &&
                !method_exists(Model::class, $column)
            ) {
                $relations[] = $column;
            }
        }

        return array_unique($relations);
    }
159762
public function getRelation($contentType = null)
    {
        if (!$this->relation instanceof Collection\Relations) {
            $this->relation = new Collection\Relations();
        }

        if ($contentType !== null) {
            return $this->relation[$contentType];
        }

        return $this->relation;
    }
777653
public function getQueueableRelations()
    {
        $relations = [];

        foreach ($this->getRelations() as $key => $relation) {
            if (method_exists($this, $key)) {
                $relations[] = $key;
            }

            if ($relation instanceof QueueableCollection) {
                foreach ($relation->getQueueableRelations() as $collectionValue) {
                    $relations[] = $key.'.'.$collectionValue;
                }
            }

            if ($relation instanceof QueueableEntity) {
                foreach ($relation->getQueueableRelations() as $entityKey => $entityValue) {
                    $relations[] = $key.'.'.$entityValue;
                }
            }
        }

        return array_unique($relations);
    }
175135
public function constrain()
	{
		return $this->related->whereEquals($this->relatedKey, $this->model->{$this->localKey});
	}
1292249
protected function getRelationshipInstance() : Relationship
    {
        $relation = $this->relationshipMethod;
        $entity = $this->parentEntity;
        $entityMap = Manager::getMapper($entity)->getEntityMap();

        return $entityMap->$relation($entity);
    }
1371446
public function filterRelations()
    {
        // Verify we can filter by relations and there are relations to filter by
        if ($this->relationsEnabled()) {
            foreach ($this->getAllRelations() as $related => $filterable) {
                // Make sure we have filterable input
                if (count($filterable) > 0) {
                    if ($this->relationIsJoined($related)) {
                        $this->filterJoinedRelation($related);
                    } else {
                        $this->filterUnjoinedRelation($related);
                    }
                }
            }
        }

        return $this;
    }
1048576
public function parentModel()
    {
        if ($this->value
            && ($relation = $this->guessRelation())
            && ($model = $this->getModel())
            && method_exists($model, $relation)) {
            return $model->$relation;
        }
    }
274805
public function getRelations()
    {
        $relations = $columns = [];

        /** @var Field $field */
        foreach ($this->builder->fields() as $field) {
            $columns[] = $field->column();
        }

        foreach (Arr::flatten($columns) as $column) {
            if (Str::contains($column, '.')) {
                list($relation) = explode('.', $column);

                if (method_exists($this->model, $relation) &&
                    $this->model->$relation() instanceof Relations\Relation
                ) {
                    $relations[] = $relation;
                }
            } elseif (method_exists($this->model, $column) &&
                !method_exists(Model::class, $column)
            ) {
                $relations[] = $column;
            }
        }

        return array_unique($relations);
    }
1126817
public function getRelation()
    {
        if (!$this->relatedTableName) {
            return null;
        }
        foreach ($this->getTable()->getRelations() as $name => $relation) {
            if ($relation->getType() == RelationMap::MANY_TO_ONE) {
                if ($relation->getForeignTable()->getName() == $this->getRelatedTableName() && array_key_exists($this->getFullyQualifiedName(), $relation->getColumnMappings())) {
                    return $relation;
                }
            }
        }
    }
1172444
private function getRelations()
	{
        if (is_null($this->relations)) {
            $builder = new RelationBuilder();
            $this->relations = $builder->build($this->data);
        }

        return $this->relations;
    }
395959
public function getRelativeOffset() {
		if($this->getParent()) {
			return $this->id - $this->getParent()->getID();
		}

		return $this->id;
	}
140403
public function getRelatedFields()
    {
        if (is_string($this->relation->toModel)) {
            throw new ValueError(
                sprintf(
                    'Related model "%s" cannot be resolved',
                    $this->relation->toModel
                )
            );
        }
        // owning side of a relation

        if (BaseOrm::RECURSIVE_RELATIONSHIP_CONSTANT == $this->fromField) {
            $this->fromField = $this;
        } elseif (is_string($this->fromField)) {
            $this->fromField = $this->scopeModel->getMeta()->getField($this->fromField);
        }

        //inverse side of a relation
        if (is_string($this->toField)) {
            $this->toField = $this->relation->toModel->getMeta()->getField($this->toField);
        } else {
            $this->toField = $this->relation->toModel->getMeta()->primaryKey;
        }

        return [$this->fromField, $this->toField];
    }
1275234
protected function guessInverseRelation()
    {
        $relation = Str::plural(class_basename($this->getParent()));

        return Str::camel($relation);
    }
880322
public function getJunction()
    {
        if ($this->relationType == 'hasAndBelongsToMany')
        {
            $tables = $this->tables;
            sort($tables);
            return implode('_', $tables);
        }
        return false;
    }
531491
protected function getRelation($name)
    {
        $relation = $this->relations[$name];
        if ($relation instanceof self || (\is_array($relation) && $relation[0] instanceof self)) {
            return $relation;
        }

        $class = 'App\\Model\\' . $relation[1];
        /** @var Model $model */
        $model = new $class();

        switch ($relation[0]) {
            case self::HAS_ONE:
                $this->relations[$name] = $model->eq($relation[2], $this->__get($this->primary))->get();
                break;
            case self::HAS_MANY:
                $this->relations[$name] = $model->eq($relation[2], $this->__get($this->primary))->select();
                break;
            case self::BELONGS_TO:
                $this->relations[$name] = $model->get($this->__get($relation[2]));
                break;
            default:
                throw new ModelException("Relation $name not found.");
        }

        return $this->relations[$name];
    }
84989
public function getOldRelations()
    {
        $oldRelations = [];
        foreach ($this->_relations as $relationName) {
            $oldRelations[$relationName] = $this->getOldRelation($relationName);
        }
        return $oldRelations;
    }