private function hydrateRelation($entity, $name, $value)
    {
        $relationClass = $this->em
            ->getClassMetadata(get_class($entity))
            ->getAssociationMapping($name)["targetEntity"]
        ;

        $relation = $entity->{"get".Inflector::camelize($name)}();
        if(in_array('id', array_keys($value))) {
            $relation = $this->em->getRepository($relationClass)->find($value['id']);
            unset($value['id']);
        } elseif(empty($relation)) {
            $relation = new $relationClass;
        }

        return $this->hydrate($relation, $value);
    }
private function hydrateRelation($entity, $name, $value)
    {
        $relationClass = $this->em
            ->getClassMetadata(get_class($entity))
            ->getAssociationMapping($name)["targetEntity"]
        ;

        $relation = $entity->{"get".Inflector::camelize($name)}();
        if(in_array('id', array_keys($value))) {
            $relation = $this->em->getRepository($relationClass)->find($value['id']);
            unset($value['id']);
        } elseif(empty($relation)) {
            $relation = new $relationClass;
        }

        return $this->hydrate($relation, $value);
    }
private function hydrateRelation ( $ entity , $ name , $ value ) { $ relationClass = $ this -> em -> getClassMetadata ( get_class ( $ entity ) ) -> getAssociationMapping ( $ name ) [ "targetEntity" ] ; $ relation = $ entity -> { "get" . Inflector :: camelize ( $ name ) } ( ) ; if ( in_array ( 'id' , array_keys ( $ value ) ) ) { $ relation = $ this -> em -> getRepository ( $ relationClass ) -> find ( $ value [ 'id' ] ) ; unset ( $ value [ 'id' ] ) ; } elseif ( empty ( $ relation ) ) { $ relation = new $ relationClass ; } return $ this -> hydrate ( $ relation , $ value ) ; }
Map and hydrate relations

@param $entity
@param $name
@param $value
@return Entity
@throws \Doctrine\ORM\Mapping\MappingException
Map and hydrate relations