private function addParentFilter(ConfigInterface $config, ModelInterface $parentModel)
    {
        $environment     = $this->getEnvironment();
        $definition      = $environment->getDataDefinition();
        $basicDefinition = $definition->getBasicDefinition();

        if (!$basicDefinition->getParentDataProvider()) {
            return;
        }

        if ($basicDefinition->getParentDataProvider() !== $parentModel->getProviderName()) {
            throw new \RuntimeException(
                \sprintf(
                    'Parent provider mismatch: %s vs. %s',
                    $basicDefinition->getParentDataProvider(),
                    $parentModel->getProviderName()
                )
            );
        }

        // Apply parent filtering, do this only for root elements.
        if ($parentCondition = $definition->getModelRelationshipDefinition()->getChildCondition(
            $basicDefinition->getParentDataProvider(),
            $basicDefinition->getRootDataProvider()
        )) {
            $baseFilter = $config->getFilter();
            $filter     = $parentCondition->getFilter($parentModel);

            if ($baseFilter) {
                $filter = \array_merge($baseFilter, $filter);
            }

            $config->setFilter($filter);
        }
    }