/** * Extracts a standard relationship array that the store expects from a raw MongoDB reference value. * * @param RelationshipMetadata $relMeta * @param mixed $reference * @return array * @throws \RuntimeException If the relationship could not be extracted. */ protected function extractRelationship(RelationshipMetadata $relMeta, $reference) { $simple = false === $relMeta->isPolymorphic(); $idKey = $this->getIdentifierKey(); $typeKey = $this->getPolymorphicKey(); if (true === $simple && is_array($reference) && isset($reference[$idKey])) { return ['id' => $reference[$idKey], 'type' => $relMeta->getEntityType()]; } elseif (true === $simple && !is_array($reference)) { return ['id' => $reference, 'type' => $relMeta->getEntityType()]; } elseif (false === $simple && is_array($reference) && isset($reference[$idKey]) && isset($reference[$typeKey])) { return ['id' => $reference[$idKey], 'type' => $reference[$typeKey]]; } else { throw new RuntimeException('Unable to extract a reference id.'); } }