Skip to content

Commit

Permalink
Handle Many To One
Browse files Browse the repository at this point in the history
  • Loading branch information
maxiloc committed Jul 20, 2015
1 parent 0e2cee3 commit c4b68c8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Indexer/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Algolia\AlgoliaSearchBundle\Indexer;

use Doctrine\Common\Persistence\Proxy;
use Doctrine\ORM\EntityManager;

use Algolia\AlgoliaSearchBundle\Exception\UnknownEntity;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c4b68c8

Please sign in to comment.