protected function scheduleRelationForInsertion($root, $child, $foreignKey)
    {
        if (!$this->entityRegistry->isRegistered($root)) {
            $this->scheduleForInsertion($root);
        }

        if (!$this->entityRegistry->isRegistered($child)) {
            $this->scheduleForInsertion($child);
        }

        $isAccessorRegistry = $this->entityRegistry->getIdAccessorRegistry();
        $this->entityRegistry->registerAggregateRootCallback(
            $root,
            $child,
            function ($root, $child) use ($foreignKey, $isAccessorRegistry) {
                $reflection = new \ReflectionProperty(get_class($child), $foreignKey);
                $reflection->setAccessible(true);
                $reflection->setValue($child, $isAccessorRegistry->getEntityId($root));
            }
        );
    }