private function getAssociationMetadataForProperty(
        ClassMetadata $resourceMetadata,
        array &$associationsMetadata,
        array
        $explodedProperty
    ) {
        if (0 === count($explodedProperty)) {
            return $resourceMetadata;
        }

        $parentResourceMetadata = $resourceMetadata;
        foreach ($explodedProperty as $index => $property) {
            if (1 <= $index) {
                $parentResourceMetadata = $associationsMetadata[$explodedProperty[$index - 1]];
            }

            if (false === $parentResourceMetadata->hasAssociation($property)) {
                throw new \RuntimeException(sprintf(
                    'Class %s::%s is not an association.',
                    $parentResourceMetadata->getName
                    (),
                    $property)
                );
            }

            if (false === isset($associationsMetadata[$property])) {
                $associationsMetadata[$property] = $this->getMetadata(
                    $parentResourceMetadata->getAssociationTargetClass($property)
                );
            }
        }

        return $associationsMetadata[end($explodedProperty)];
    }