public function getModel($modelId, $providerName = null)
    {
        if (\is_string($modelId)) {
            try {
                $modelId = ModelId::fromValues($providerName, $modelId);
            } catch (\Exception $swallow) {
                $modelId = ModelId::fromSerialized($modelId);
            }
        }

        if (!($modelId instanceof ModelIdInterface)) {
            throw new \InvalidArgumentException('Invalid model id passed: ' . \var_export($modelId, true));
        }

        $definition       = $this->environment->getDataDefinition();
        $parentDefinition = $this->environment->getParentDataDefinition();
        $dataProvider     = $this->environment->getDataProvider($modelId->getDataProviderName());
        $config           = $dataProvider->getEmptyConfig();

        if ($definition->getName() === $modelId->getDataProviderName()) {
            $propertyDefinition = $definition->getPropertiesDefinition();
        } elseif ($parentDefinition->getName() === $modelId->getDataProviderName()) {
            $propertyDefinition = $parentDefinition->getPropertiesDefinition();
        } else {
            throw new \InvalidArgumentException('Invalid provider name ' . $modelId->getDataProviderName());
        }

        $properties = [];

        // Filter real properties from the property definition.
        foreach ($propertyDefinition->getPropertyNames() as $propertyName) {
            if ($dataProvider->fieldExists($propertyName)) {
                $properties[] = $propertyName;

                continue;
            }

            // @codingStandardsIgnoreStart
            @\trigger_error(
                'Only real property is allowed in the property definition.' .
                'This will no longer be supported in the future.',
                E_DEPRECATED
            );
            // @codingStandardsIgnoreEnd
        }
        $config->setId($modelId->getId())->setFields($properties);

        return $dataProvider->fetch($config);
    }