GraphAware\Neo4j\OGM\Tests\Integration\Model\User::setCity PHP Метод

setCity() публичный Метод

public setCity ( City $city, $since = null )
$city City
    public function setCity(City $city, $since = null)
    {
        $since = null !== $since ? $since : 123;
        $rel = new LivesIn($this, $city, $since);
        $this->setLivesIn($rel);
        $city->addHabitant($rel);
    }

Usage Example

 public function testLazyLoadedEntitiesAreManagedForRemoval()
 {
     $this->clearDb();
     $michal = new User('michal');
     $daniela = new User('daniela');
     $city = new City('London');
     $michal->setCity($city);
     $daniela->setCity($city);
     $this->em->persist($city);
     $this->em->persist($michal);
     $this->em->persist($daniela);
     $this->em->flush();
     $this->assertGraphExist('(m:User {login:"******"})-[:LIVES_IN {since:123}]->(c:City {name:"London"})<-[:LIVES_IN {since:123}]-(d:User {login:"******"})');
     $this->em->clear();
     /** @var City $london */
     $london = $this->em->getRepository(City::class)->findOneBy('name', 'London');
     $this->assertInstanceOf(LazyRelationshipCollection::class, $london->getHabitants());
     $this->assertCount(2, $london->getHabitants());
     /** @var LivesIn $livesIn */
     foreach ($london->getHabitants() as $livesIn) {
         $this->assertInstanceOf(User::class, $livesIn->getUser());
         $this->assertInstanceOf(City::class, $livesIn->getCity());
         $this->assertEquals(123, $livesIn->getSince());
         $this->assertInstanceOf(LivesIn::class, $livesIn->getUser()->getLivesIn());
     }
     $u = $london->getHabitants()[0];
     $london->getHabitants()->removeElement($u);
     $u->getUser()->removeCity($u->getCity());
     $this->em->flush();
 }
All Usage Examples Of GraphAware\Neo4j\OGM\Tests\Integration\Model\User::setCity