protected function applyOverridesForRelationships()
    {
        $overrides = array_get($this->overrides, 'relationships');

        if (empty($overrides)) return;

        $removeRelations = [];

        foreach ($overrides as $overrideName => $override) {

            // find the relationship
            foreach (['normal', 'image', 'file', 'checkbox'] as $type) {

                foreach ($this->model['relationships'][ $type ] as $name => &$relationData) {

                    if ($name === $overrideName) {

                        // apply overrides and change the model data

                        $newName        = array_get($override, 'name');
                        $preventReverse = array_get($override, 'prevent_reverse', false);
                        $reverseName    = array_get($override, 'reverse_name', false);

                        if ($preventReverse) {
                            $relationData['prevent_reverse'] = true;
                        }

                        if ( ! empty($reverseName)) {
                            $relationData['reverse_name'] = $reverseName;
                        }

                        if ( ! empty($newName)) {

                            $this->model['relationships'][ $type ][ $newName ] = $relationData;

                            $removeRelations[] = $type . '.' . $overrideName;
                            $removeRelations = array_diff($removeRelations, [ $newName ]);
                        }


                        $this->context->log(
                            "Override applied for relationship {$overrideName} on module {$this->moduleId}."
                        );

                        break 2;
                    }
                }
            }
        }

        unset($relationData);

        // remove now 'moved' relationships
        array_forget($this->model['relationships'], $removeRelations);
    }