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);
    }