예제 #1
0
 protected function updateCollection()
 {
     foreach ($this->forAdd as $newEntity) {
         $this->wrappedEntity->addToCollection($this->component->name, $newEntity);
         $this->wrappedEntity->getEntityManager()->persist($newEntity);
     }
     foreach ($this->forRemoval as $entityForRemove) {
         $this->wrappedEntity->removeFromCollection($this->component->name, $entityForRemove);
         if ($this->type == ClassMetadata::ONE_TO_MANY && $this->wrappedEntity->getEntityManager()->contains($entityForRemove)) {
             $this->wrappedEntity->getEntityManager()->remove($entityForRemove);
         }
     }
 }
예제 #2
0
 /**
  * @param WrappedEntity $wrappedEntity
  * @param Container $component
  * @param array $association
  * @return null|object
  */
 protected function getRelatedEntity(WrappedEntity $wrappedEntity, Container $component, $association)
 {
     $relatedEntity = $wrappedEntity->getValue($component->name);
     if ($relatedEntity === NULL) {
         $className = $association['targetEntity'];
         $entityManager = $wrappedEntity->getEntityManager();
         $metadata = $entityManager->getClassMetadata($className);
         $identifierFields = $metadata->identifier;
         $data = $component->getValues(TRUE);
         $relatedEntityIdentifier = $this->getIdentifierFromArray($identifierFields, $data);
         if ($relatedEntityIdentifier) {
             $repository = $entityManager->getRepository($className);
             $relatedEntity = $repository->find($relatedEntityIdentifier);
         }
         if (!$relatedEntity) {
             $relatedEntity = $metadata->newInstance();
         }
     }
     return $relatedEntity;
 }