{@inheritdoc}

Overloaded to support relationships.
349816
public function get($key)
    {
        if (true === $this->isRelationship($key)) {
            return $this->getRelationship($key);
        }
        return parent::get($key);
    }
1087105
function addRelationshipsToJDL() {
  for (let i = 0, entityNames = Object.keys(configuration.entities); i < entityNames.length; i++) {
    dealWithRelationships(configuration.entities[entityNames[i]].relationships, entityNames[i]);
  }
}
1097010
public function set(RelationshipInterface $relationship): RelationshipCollectionInterface
    {
        $this->collection[$relationship->name()] = $relationship;

        return $this;
    }
173144
private static function relations()
    {
        $files = ['OneToOne', 'OneToMany', 'ManyToMany', 'BelongsTo'];
        $folder = static::$root.'MVC/Relations'.'/';

        self::call($files, $folder);

        $files = ['ManyRelationException', 'ModelNotFindedException'];
        $folder = static::$root.'MVC/Relations/Exceptions'.'/';

        self::call($files, $folder);
    }
912697
public function setRelationship($value, $key = '')
	{
		if (is_array($value)) {

			$class = __NAMESPACE__ . '\\' . str_singular($key);

			if (class_exists($class)) {

				// Check to see if the key value is plural or singular
				// if it is plural then we create a collection
				// otherwise we instantiate the class and add a single item to the relationship
				if (str_singular($key) == $key) {
					$this->addRelationship(new $class($value));
				}
				else {
					$collection = $class::newCollection($value);
					$this->addRelationship($collection);
				}
			}
		}
		elseif ($value instanceof Collection) {
			$this->addRelationship($value);
		}
		elseif ($value instanceof BaseModel) {
			$this->addRelationship($value);
		}
	}
506234
private function resolveHasOneOrMany($definition)
    {
        foreach (array_merge($definition->relations['hasMany'], $definition->relations['hasOne']) as $relation) {
            $counterMeta      = $this->getMeta($relation->entity);
            $counterRelations = $counterMeta->relations;

            foreach ($counterRelations['belongsTo'] as $belongsTo) {
                if ($belongsTo->entity == $definition->name && $belongsTo->reference == $relation->reference) {
                    break 2;
                }
            }

            // No existing counter-relation found; create it.
            $belongsTo = new BelongsTo(
                [
                    'name'      => $this->normalise($definition->name),
                    'entity'    => $definition->name,
                    'reference' => $relation->reference,
                ]
            );

            $this->entityDefinitions[$counterMeta->name]->relations['belongsTo'][$belongsTo->name] = $belongsTo;
        }
    }
636478
public function readExtendedMetadata($meta, array &$config)
    {
        $class = $this->getMetaReflectionClass($meta);
        /* @var $relationOverrides RelationOverrides */
        if (!($relationOverrides = $this->reader->getClassAnnotation($class, RelationOverrides::class))) {
            return;
        }

        $config['relationOverrides'] = [];

        /* @var $relationOverride RelationOverride */
        foreach ($relationOverrides->value as $relationOverride) {
            $fieldName = $relationOverride->name;

            if (!$class->hasProperty($fieldName)) {
                throw new MappingException(sprintf(
                    "Property %s doesn't exist",
                    $meta->getName() . '::$' . $fieldName
                ));
            }

            if ($meta->isMappedSuperclass && !$class->getProperty($fieldName)->isPrivate() ||
                $meta->isInheritedField($fieldName) ||
                $meta->hasField($fieldName))
            {
                continue;
            }

            $config['relationOverrides'][] = $relationOverride;
        }
    }
843638
public function hasIncludedRelationships(): bool
    {
        if ($this->includedRelationships === null) {
            $this->setIncludedRelationships();
        }

        return empty($this->includedRelationships) === false;
    }
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;
    }
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;
    }
1330244
private function buildRelationships($includeKey, $relationships, $includeObject, $key)
    {
        $relationships = $this->addIncludekeyToRelationsIfNotSet($includeKey, $relationships);

        if ($this->isNull($includeObject)) {
            $relationship = $this->null();
        } elseif ($this->isEmpty($includeObject)) {
            $relationship = [
                'data' => [],
            ];
        } elseif ($this->isCollection($includeObject)) {
            $relationship = ['data' => []];

            $relationship = $this->addIncludedDataToRelationship($includeObject, $relationship);
        } else {
            $relationship = [
                'data' => [
                    'type' => $includeObject['data']['type'],
                    'id' => $includeObject['data']['id'],
                ],
            ];
        }

        $relationships[$includeKey][$key] = $relationship;

        return $relationships;
    }
231760
private function fillRelationshipAsSingleResource($data, $relationship, $key)
    {
        $data['data']['relationships'][$key] = $relationship[0];

        if ($this->shouldIncludeLinks()) {
            $data['data']['relationships'][$key] = array_merge([
                'links' => [
                    'self' => "{$this->baseUrl}/{$data['data']['type']}/{$data['data']['id']}/relationships/$key",
                    'related' => "{$this->baseUrl}/{$data['data']['type']}/{$data['data']['id']}/$key",
                ],
            ], $data['data']['relationships'][$key]);

            return $data;
        }
        return $data;
    }
451444
public function getRelationships()
    {
        if (empty(static::$relationHooks)) {
            $hooks = [];

            $rels = $this->getRelationshipsFromMethods(true);

            $this->getRelationshipsUnknownPolyMorph($rels, $hooks);

            $this->getRelationshipsKnownPolyMorph($rels, $hooks);

            $this->getRelationshipsHasOne($rels, $hooks);

            $this->getRelationshipsHasMany($rels, $hooks);

            static::$relationHooks = $hooks;
        }

        return static::$relationHooks;
    }
444891
public function getToManyRelationship(string $relationship): ToManyRelationship
    {
        $data = $this->getResource();

        if (isset($data["relationships"][$relationship]["data"]) === false) {
            throw $this->exceptionFactory->createRelationshipNotExistsException($relationship);
        }

        $resourceIdentifiers = [];
        foreach ($data["relationships"][$relationship]["data"] as $item) {
            $resourceIdentifiers[] = ResourceIdentifier::fromArray($item, $this->exceptionFactory);
        }

        return new ToManyRelationship($resourceIdentifiers);
    }
1307616
protected function getRelationshipDataRepresentation(RelationshipDataInterface $data): ?array
    {
        if ($data->isResource() === true) {
            return $this->getIdentifierRepresentationFromResource($data->getResource());
        } elseif ($data->isIdentifier() === true) {
            return $this->getIdentifierRepresentation($data->getIdentifier());
        } elseif ($data->isCollection() === true) {
            $representation = [];
            foreach ($data->getIdentifiers() as $identifier) {
                \assert($identifier instanceof IdentifierInterface);
                $representation[] = $this->getIdentifierRepresentation($identifier);
            }

            return $representation;
        }

        \assert($data->isNull() === true);

        return null;
    }
28501
public function setRelated($value)
    {
        $this->loadData(true);

        if (is_null($value)) {
            $value = [];
        }

        if (!is_array($value)) {
            throw new RelationException("HasMany relation can only be set with array of entities");
        }

        //Do not add items twice
        $matched = [];
        foreach ($value as $index => $record) {
            if (is_null($record)) {
                unset($value[$index]);
                continue;
            }

            $this->assertValid($record);
            if (!empty($instance = $this->matchOne($record))) {
                $matched[] = $instance;
                unset($value[$index]);
            }
        }

        //Unlink records
        foreach (array_diff($this->instances, $matched) as $record) {
            $this->unlink($record);
        }

        //Add new record
        foreach ($value as $record) {
            $this->link($record);
        }
    }
1011034
public function indexRelationship(
        string $name,
        iterable $relationshipFilters = null,
        iterable $relationshipSorts = null
    ) {
        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;

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

        $modelClass = $builder->getModelClass();
        $data       = $isExpectMany === true ?
            $this->fetchResources($builder, $modelClass) : $this->fetchResource($builder, $modelClass);

        return $data;
    }