private function entityFieldToArray(array $data, $entity, $path)
    {
        $parts = explode('.', $path, 2);

        if (count($parts) === 1) {
            if ($entity instanceof \Traversable) {
                $data = [];

                foreach ($entity as $item) {
                    $id = $this->em->getClassMetadata(get_class($item))->getSingleIdentifierColumnName();

                    $data[] = [
                        $id => $this->propertyAccessor->getValue($item, $id),
                        $parts[0] => $this->propertyAccessor->getValue($item, $parts[0]),
                    ];
                }
            } else {
                if (count($data) === 0) {
                    $data = [];
                    $id = $this->em->getClassMetadata(get_class($entity))->getSingleIdentifierColumnName();
                    $data[$id] = $this->propertyAccessor->getValue($entity, $id);
                }

                $data[$parts[0]] = $this->propertyAccessor->getValue($entity, $parts[0]);
            }

            return $data;
        } else {
            $data[$parts[0]] = $this->entityFieldToArray(
                isset($data[$parts[0]]) ? $data[$parts[0]] : [],
                $this->propertyAccessor->getValue($entity, $parts[0]),
                $parts[1]
            );

            return $data;
        }
    }