entityManager = $entityManager; $this->router = $router; } public function addRelations($object, ClassMetadataInterface $classMetadata) { $relations = array(); $parts = explode('\\', $classMetadata->getName()); $self_route = 'get_' . strtolower(array_pop($parts)); if ($this->routeExists($self_route) ) { $relations[] = new Hateoas\Relation( 'self', new Hateoas\Route( $self_route, array('id' => 'expr(object.getId())') ) ); } $metadata = $this->entityManager->getClassMetadata($classMetadata->getName()); foreach($metadata->getAssociationMappings() as $mapping) { $route_name = $self_route . '_' . strtolower($mapping['fieldName']); if ($this->routeExists($route_name)) { $relations[] = new Hateoas\Relation( $mapping['fieldName'], new Hateoas\Route( $route_name, array('id' => 'expr(object.getId())') ) ); } } // You need to return the relations // Adding the relations to the $classMetadata won't work return $relations; } protected function routeExists($name) { return $this->router->getRouteCollection()->get($name) instanceof Route; } }