GraphAware\Neo4j\OGM\Tests\Integration\Model\BothTest::addFriend PHP Method

addFriend() public method

public addFriend ( BothTest $bothTest )
$bothTest BothTest
    public function addFriend(BothTest $bothTest)
    {
        $this->friends->add(new BothRel($this, $bothTest));
    }

Usage Example

 public function testRelationshipEntityBoth()
 {
     $this->clearDb();
     $b1 = new BothTest('a');
     $b2 = new BothTest('b');
     $b3 = new BothTest('c');
     $b1->addFriend($b2);
     $b1->addFriend($b3);
     $this->em->persist($b1);
     $this->em->flush();
     $this->assertGraphExist('(b:Both {name:"b"})-[:FRIEND]-(a:Both {name:"a"})-[:FRIEND]-(c:Both {name:"c"})');
     $this->em->clear();
     $repository = $this->em->getRepository(BothTest::class);
     $entities = $repository->findAll(['order' => ['name' => BaseRepository::ORDER_ASC]]);
     $this->assertEquals('a', $entities[0]->getName());
     $this->assertEquals('c', $entities[2]->getName());
     $a = $entities[0];
     $this->assertCount(2, $a->getFriends());
     foreach ($a->getFriends() as $friend) {
         $this->assertInstanceOf(BothRel::class, $friend);
         $this->assertTrue(in_array($friend->getEndNode()->getName(), ['b', 'c'], true));
     }
 }