diff --git a/lib/HireVoice/Neo4j/EntityManager.php b/lib/HireVoice/Neo4j/EntityManager.php index 2570eb0..aa8774c 100644 --- a/lib/HireVoice/Neo4j/EntityManager.php +++ b/lib/HireVoice/Neo4j/EntityManager.php @@ -424,7 +424,7 @@ public function getRepository($class) * @param Object $b * @param string $direction */ - public function addRelation($name, $a, $b, $direction) + public function addRelation($name, $a, $b, $direction = 'from') { if(strtolower($direction) == 'to'){ $tmp = $b; diff --git a/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php b/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php index 633c0f3..c40be97 100644 --- a/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php +++ b/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php @@ -638,6 +638,46 @@ function testRemoveEntity() $this->assertTrue(true); } + + public function testAddRelationWithoutSpecifyingDirection() + { + $em = $this->getEntityManager(); + + $movie = new Entity\Movie; + $movie->setTitle('Terminator'); + $em->persist($movie); + + $cinema = new Entity\Cinema; + $cinema->setName('UGC'); + $em->persist($cinema); + + $em->flush(); + + $movie = $em->reload($movie); + $cinema = $em->reload($cinema); + + $em->addRelation('presentedMovie', $movie, $cinema); + } + + public function testAddRelationBySpecifyingDirection() + { + $em = $this->getEntityManager(); + + $movie = new Entity\Movie; + $movie->setTitle('Terminator'); + $em->persist($movie); + + $cinema = new Entity\Cinema; + $cinema->setName('UGC'); + $em->persist($cinema); + + $em->flush(); + + $movie = $em->reload($movie); + $cinema = $em->reload($cinema); + + $em->addRelation('presentedMovie', $movie, $cinema, 'to'); + } } /**