From c4b68c83c9ccd50a7ebad203e3f2c0413f3b237e Mon Sep 17 00:00:00 2001 From: Maxime Locqueville Date: Mon, 20 Jul 2015 16:08:04 +0200 Subject: [PATCH] Handle Many To One --- Indexer/Indexer.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Indexer/Indexer.php b/Indexer/Indexer.php index ed3990c1..ce414183 100644 --- a/Indexer/Indexer.php +++ b/Indexer/Indexer.php @@ -2,6 +2,7 @@ namespace Algolia\AlgoliaSearchBundle\Indexer; +use Doctrine\Common\Persistence\Proxy; use Doctrine\ORM\EntityManager; use Algolia\AlgoliaSearchBundle\Exception\UnknownEntity; @@ -260,6 +261,18 @@ public function scheduleEntityDeletion($entity, array $originalData = null) ); } + + function isEntity(EntityManager $em, $class) + { + if (is_object($class)) { + $class = ($class instanceof Proxy) + ? get_parent_class($class) + : get_class($class); + } + + return ! $em->getMetadataFactory()->isTransient($class); + } + /** * OOP? Encapsulation? No thanks! :) * http://php.net/manual/en/closure.bind.php @@ -287,6 +300,14 @@ private function extractPropertyValue($entity, $field) }, $value); } + if (is_object($value) && $this->isEntity($this->em, $value)) + { + $this->discoverEntity($value, $this->em); + + $value = $this->getFieldsForAlgolia($value); + } + + return $value; }