protected function extractRelationships(array $data, EntityMetadata $metadata)
    {
        $flattened = [];
        if (!isset($data['relationships']) || !is_array($data['relationships'])) {
            return $flattened;
        }

        foreach ($metadata->getRelationships() as $key => $relMeta) {
            if (!isset($data['relationships'][$key])) {
                continue;
            }
            $rel = $data['relationships'][$key];
            // Need to use array_key_exists over isset because 'null' is valid. Creating a key map for each relationship is too costly since every relationship needs the data check.
            if (false === array_key_exists('data', $rel)) {
                throw NormalizerException::badRequest(sprintf('The "data" member was missing from the payload for relationship "%s"', $key));
            }

            if (empty($rel['data'])) {
                $flattened[$key] = $relMeta->isOne() ? null : [];
                continue;
            }

            if (!is_array($rel['data'])) {
                throw NormalizerException::badRequest(sprintf('The "data" member is not valid in the payload for relationship "%s"', $key));
            }

            if (true === $relMeta->isOne() && true === $this->isSequentialArray($rel['data'])) {
                throw NormalizerException::badRequest(sprintf('The data payload for relationship "%s" is malformed. Data types of "one" must be an associative array, sequential found.', $key));
            }
            if (true === $relMeta->isMany() && false === $this->isSequentialArray($rel['data'])) {
                throw NormalizerException::badRequest(sprintf('The data payload for relationship "%s" is malformed. Data types of "many" must be a sequential array, associative found.', $key));
            }
            $flattened[$key] = $rel['data'];
        }
        return $flattened;
    }