コード例 #1
0
 /**
  * Insert data
  *
  * @param object $model Object that you want to insert
  * @param bool $flush Insert to database or not
  * @return object
  */
 public function persist($model, $flush = true)
 {
     $this->entityManager->persist($model);
     //Remove in database
     if ($flush) {
         $this->entityManager->flush();
     }
     return $model;
 }
コード例 #2
0
 public function testRelationRemove()
 {
     $eventManager = $this->getEventManagerWithListenerExpectations(array('prePersist' => 3, 'postPersist' => 3, 'preRelationCreate' => 1, 'postRelationCreate' => 1, 'preRelationRemove' => 1, 'postRelationRemove' => 1));
     $movie = new Entity\Movie();
     $movie->setTitle('Terminator');
     $actor = new Entity\Person();
     $actor->setFirstName('Arnold');
     $movie->addActor($actor);
     $this->em->setEventManager($eventManager);
     $this->em->persist($movie);
     $this->em->flush();
     $movie = $this->em->find(get_class($movie), $movie->getId());
     $actor = $movie->getActors()->first();
     $movie->removeActor($actor);
     $this->em->persist($movie);
     $this->em->flush();
 }