예제 #1
0
 /**
  * Returns the values of the identifier fields of an entity
  *
  * Doctrine must know about this entity, that is, the entity must already
  * be persisted or added to the identity map before. Otherwise an
  * exception is thrown.
  *
  * @param  object $entity  The entity for which to get the identifier
  * @throws FormException   If the entity does not exist in Doctrine's
  *                         identity map
  */
 public function getIdentifierValues($entity)
 {
     if (!$this->unitOfWork->isInIdentityMap($entity)) {
         throw new FormException('Entities passed to the choice field must be managed');
     }
     return $this->unitOfWork->getEntityIdentifier($entity);
 }
 /**
  * @param ClassMetadata $class
  * @param array         $entityData
  * @param string        $revType
  */
 private function saveRevisionEntityData($class, $entityData, $revType)
 {
     $params = array($this->getRevisionId(), $revType);
     $types = array(\PDO::PARAM_INT, \PDO::PARAM_STR);
     foreach ($class->fieldNames as $field) {
         $params[] = $entityData[$field];
         $types[] = $class->fieldMappings[$field]['type'];
     }
     foreach ($class->associationMappings as $field => $assoc) {
         if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             if ($entityData[$field] !== null) {
                 $relatedId = $this->uow->getEntityIdentifier($entityData[$field]);
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
                 if ($entityData[$field] === null) {
                     $params[] = null;
                     $types[] = \PDO::PARAM_STR;
                 } else {
                     $params[] = $relatedId[$targetClass->fieldNames[$targetColumn]];
                     $types[] = $targetClass->getTypeOfColumn($targetColumn);
                 }
             }
         }
     }
     $this->conn->executeUpdate($this->getInsertRevisionSQL($class), $params, $types);
 }