@param iterable $relationships

@return array
492169
protected function getRelationshipsRepresentation(iterable $relationships): array
    {
        $representation = [];
        foreach ($relationships as $name => $relationship) {
            \assert(\is_string($name) === true && empty($name) === false);
            \assert($relationship instanceof RelationshipInterface);
            $representation[$name] = $this->getRelationshipRepresentation($relationship);
        }

        return $representation;
    }
1304412
private function iterableToArray(iterable $iterable): array
    {
        $result = [];

        foreach ($iterable as $key => $value) {
            $result[$key] = $value instanceof Generator ? $this->iterableToArray($value) : $value;
        }

        return $result;
    }
843739
public function readMany($keys)
    {
        $cacheKeys = [];
        foreach ($keys as $key) {
            $cacheKeys[] = $this->_key($key);
        }

        $values = $this->_Memcached->getMulti($cacheKeys);
        $return = [];
        foreach ($keys as &$key) {
            $return[$key] = array_key_exists($this->_key($key), $values) ?
                $values[$this->_key($key)] : false;
        }

        return $return;
    }
807050
public function getRelations()
    {
        if (!isset($this->relationships)) {
            $this->relationships = array();
            // load them manually
            $mm = $this->getModelsManager();
            $relationships = $mm->getRelations(get_class($this));
            // Temporary fix because $mm->getRelations() doesn't support hasManyToMany relations right now.
            // get them separately and merge them
            $mtmRelationships = $mm->getHasManyToMany($this);

            $relationships = array_merge($relationships, $mtmRelationships);

            foreach ($relationships as $relation) {
                // todo load custom relationship
                $this->relationships[] = new Relation($relation, $mm);
            }
        }
        return $this->relationships;
    }
588390
protected function getRelationshipRepresentation(RelationshipInterface $relationship): array
    {
        $representation = [];

        if ($relationship->hasLinks() === true) {
            $representation[DocumentInterface::KEYWORD_LINKS] =
                $this->getLinksRepresentation($this->getUrlPrefix(), $relationship->getLinks());
        }

        if ($relationship->hasData() === true) {
            $representation[DocumentInterface::KEYWORD_DATA] = $this->getRelationshipDataRepresentation(
                $relationship->getData()
            );
        }

        if ($relationship->hasMeta() === true) {
            $representation[DocumentInterface::KEYWORD_META] = $relationship->getMeta();
        }

        return $representation;
    }
694258
protected function getLinksListRepresentation(?string $prefix, iterable $links): array
    {
        $result = [];

        foreach ($links as $link) {
            \assert($link instanceof BaseLinkInterface);
            $result[] = $link->canBeShownAsString() === true ?
                $link->getStringRepresentation($prefix) : $link->getArrayRepresentation($prefix);
        }

        return $result;
    }
284518
public function getHasOnes()
    {
        $modelNameSpace = $this->relation->getReferencedModel();
        $list = [];
        $relationships = $this->modelManager->getRelations($modelNameSpace);
        foreach ($relationships as $relation) {
            $refType = $relation->getType();
            if ($refType == 1) {
                $list[] = $relation->getReferencedModel();
            }
        }

        return $list;
    }
1089640
protected function parseWithRelations(array $relations)
    {
        $results = [];

        foreach ($relations as $name => $constraints) {
            // If the "relation" value is actually a numeric key, we can assume that no
            // constraints have been specified for the eager load and we'll just put
            // an empty Closure with the loader so that we can treat all the same.
            if (is_numeric($name)) {
                $name = $constraints;

                list($name, $constraints) = (mb_strpos($name, ':') !== false)
                            ? $this->createSelectWithConstraint($name)
                            : [$name, function () {
                                //
                            }];
            }

            // We need to separate out any nested includes. Which allows the developers
            // to load deep relationships using "dots" without stating each level of
            // the relationship with its own key in the array of eager load names.
            $results = $this->addNestedWiths($name, $results);

            $results[$name] = $constraints;
        }

        return $results;
    }
84206
public function with($relationships)
    {
        foreach ($this->resources as $resource) {
            $resource->with($relationships);
        }

        return $this;
    }
541504
private function getRelations(Repository $repository, array $relations = [])
    {
        // if we have relation array passed, ignore request input
        if (count($relations) === 0) {
            $relations = Input::get('with');

            if (!is_array($relations)) {
                $relations = $this->inputService->decode('with');
            }
        }

        $result = [];
        $repo_relations = $repository->relations();
        foreach ($relations as $key => $value) {
            if (in_array($key, $repo_relations)) {
                $result[] = $key;
            } elseif (in_array($value, $repo_relations)) {
                $result[] = $value;
            }
        }

        return $result;
    }
334901
protected function fillRelationships($data, $relationships)
    {
        if ($this->isCollection($data)) {
            foreach ($relationships as $key => $relationship) {
                $data = $this->fillRelationshipAsCollection($data, $relationship, $key);
            }
        } else { // Single resource
            foreach ($relationships as $key => $relationship) {
                $data = $this->fillRelationshipAsSingleResource($data, $relationship, $key);
            }
        }

        return $data;
    }
241062
public function whereRelations(array $relations)
    {
        $instance = $this->whereStrategyInstance();

        $instance->whereStrategy()->whereRelations($relations);

        return $instance;
    }
63986
public function indexRelationshipIdentities(
        string $name,
        iterable $relationshipFilters = null,
        iterable $relationshipSorts = null
    ): array {
        assert(
            $this->getModelSchemas()->hasRelationship($this->getModelClass(), $name),
            "Relationship `$name` do not exist in model `" . $this->getModelClass() . '`'
        );

        // depending on the relationship type we expect the result to be either single resource or a collection
        $relationshipType = $this->getModelSchemas()->getRelationshipType($this->getModelClass(), $name);
        $isExpectMany     = $relationshipType === RelationshipTypes::HAS_MANY ||
            $relationshipType === RelationshipTypes::BELONGS_TO_MANY;
        if ($isExpectMany === false) {
            throw new InvalidArgumentException($this->getMessage(Messages::MSG_ERR_INVALID_ARGUMENT));
        }

        list ($targetModelClass) = $this->getModelSchemas()->getReverseRelationship($this->getModelClass(), $name);
        $targetPk = $this->getModelSchemas()->getPrimaryKey($targetModelClass);

        $builder = $this->createReadRelationshipBuilder($name, $relationshipFilters, $relationshipSorts, [$targetPk]);

        $modelClass = $builder->getModelClass();
        /** @var Generator $data */
        $data   = $this->fetchColumn($builder, $modelClass, $targetPk);
        $result = iterator_to_array($data);

        return $result;
    }
315274
protected function relationshipsToArray(): array
    {
        $relationships = [];

        foreach ($this->relationships as $name => $relationship)
        {
            $relationships[$name] = $relationship->toArray();
        }

        return $relationships;
    }
669039
private function addIncludekeyToRelationsIfNotSet($includeKey, $relationships)
    {
        if (!array_key_exists($includeKey, $relationships)) {
            $relationships[$includeKey] = [];
            return $relationships;
        }

        return $relationships;
    }
77442
public function resolvedRelationshipKeys(): array
    {
        $includeMap = $this->includeMap();

        $keys = [];
        foreach ($this->resolvedIncludeKeys() as $includeKey) {
            $relations = $includeMap[$includeKey]['relation'] ?? [];
            if (\count($relations) > 0) {
                array_push($keys, ...$relations);
            }
        }

        return array_unique($keys);
    }
579967
protected function parseRelations(array $relations)
	{
		$results = array();

		foreach ($relations as $name => $constraints)
		{
			// If the "relation" value is actually a numeric key, we can assume that no
			// constraints have been specified for the eager load and we'll just put
			// an empty Closure with the loader so that we can treat all the same.
			if (is_numeric($name))
			{
				$f = function() {};

				list($name, $constraints) = array($constraints, $f);
			}

			// We need to separate out any nested includes. Which allows the developers
			// to load deep relationships using "dots" without stating each level of
			// the relationship with its own key in the array of eager load names.
			$results = $this->parseNested($name, $results);

			$results[$name] = $constraints;
		}

		return $results;
	}