public function primeReferences(ClassMetadata $class, $documents, $attributeName, $refresh, $readOnly, $primer = null)
    {
        $data          = $this->parseDotSyntaxForPrimer($attributeName, $class, $documents);
        $mapping       = $data['mapping'];
        $attributeName = $data['attributeName'];
        $class         = $data['class'];
        $documents     = $data['documents'];

        /* Inverse-side references would need to be populated before we can
         * collect references to be primed. This is not supported.
         */
        if (!$mapping->reference || !$mapping->isOwningSide) {
            throw new \InvalidArgumentException(sprintf('Attribute "%s" is not the owning side of a reference relationship in class "%s"', $attributeName, $class->name));
        }

        if ($primer !== null && !is_callable($primer)) {
            throw new \InvalidArgumentException('$primer is not callable');
        }

        $primer = $primer ?: $this->defaultPrimer;

        /** @var PersistentCollectionInterface $document */
        foreach ($documents as $document) {
            $value = $class->getAttributeValue($document, $attributeName);

            /* The attribute will need to be either a Proxy (reference-one) or
             * PersistentCollection (reference-many) in order to prime anything.
             */
            if (!is_object($value)) {
                continue;
            }

            if ($mapping->isOne() && $value instanceof Proxy && !$value->__isInitialized()) {
                $identifier = $this->uow->getDocumentIdentifier($value);
                $className  = $identifier->class->getName();

                $this->groupedIds[$className][$identifier->getSerialized()] = $identifier;
            } elseif ($mapping->isMany() && $value instanceof PersistentCollectionInterface) {
                $this->addManyReferences($value);
            }
        }

        foreach ($this->groupedIds as $className => $ids) {
            $class = $this->dm->getClassMetadata($className);

            call_user_func($primer, $this->dm, $class, array_values($ids), $refresh, $readOnly);
        }
    }