/** {@inheritdoc} */
 public function getFieldMapping($fieldName)
 {
     if (!$this->hasField($fieldName)) {
         throw new MetadataException("Field '{$fieldName}' not found in class '{$this->getClass()}'.");
     }
     return $this->classMetadata->getFieldMapping($fieldName);
 }
Exemple #2
0
 /**
  * @param object $entity
  * @return int
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 public function insert($entity)
 {
     $data = [];
     $types = [];
     $idColumn = false;
     foreach ($this->metaData->getColumnNames() as $columnName) {
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $mapping = $this->metaData->getFieldMapping($fieldName);
         if (isset($mapping['id'])) {
             if (isset($mapping['nullable']) && $mapping['nullable']) {
                 continue;
             }
             if (!$entity->{$fieldName}) {
                 $idColumn = $fieldName;
             }
         }
         $typeName = $this->metaData->getTypeOfColumn($fieldName);
         $type = \Doctrine\DBAL\Types\Type::getType($typeName);
         $value = $type->convertToDatabaseValue($entity->{$fieldName}, $this->em->getConnection()->getDatabasePlatform());
         $types[$columnName] = $type->getBindingType();
         $data[$columnName] = $value;
     }
     $result = $this->em->getConnection()->insert($this->metaData->getTableName(), $data, $types);
     if ($result) {
         if ($idColumn) {
             return $this->em->getConnection()->lastInsertId($this->metaData->getTableName() . '_id_seq');
         }
         return $result;
     }
     return false;
 }
 /**
  * funkcja zwraca domyslną konfiguracje dla pola formularza
  *
  * @param $fieldName
  * @param array $properties
  * @return array
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 protected function configure($fieldName, array $properties = array())
 {
     /**
      * informacje o encji
      */
     if (null === $this->metadata) {
         $this->metadata = $this->getEntityManager()->getClassMetadata(get_class($this->getObject()));
     }
     $fieldMeta = (object) $this->metadata->getFieldMapping($fieldName);
     return array_replace_recursive(array('required' => true, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'StripTags')), 'properties' => array('required' => true), 'validators' => array('NotEmpty' => array('name' => 'NotEmpty', 'options' => array('messages' => array(Validator\NotEmpty::IS_EMPTY => 'FieldCannotBeEmpty'))), 'StringLength' => array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'max' => $fieldMeta->length, 'messages' => array('stringLengthTooLong' => 'StringLengthTooLong'))))), $properties);
 }
 /**
  * @param Builder\Metadata $meta
  * @param \Doctrine\ORM\Mapping\ClassMetadata $cm
  */
 private function loadMeta(Builder\Metadata $meta, \Doctrine\ORM\Mapping\ClassMetadata $cm)
 {
     $type = null;
     if ($cm->hasField($meta->name)) {
         $map = $cm->getFieldMapping($meta->name);
         $type = $map['type'];
         switch ($type) {
             case 'smallint':
             case 'bigint':
                 $type = 'integer';
                 break;
             default:
                 break;
         }
         if (!isset($map['nullable']) || $map['nullable'] === false && !isset($meta->conditions['required'])) {
             $meta->conditions['required'] = true;
         }
         if (isset($map['length']) && $map['length'] && !isset($meta->conditions['maxLenght'])) {
             $meta->conditions['maxLength'] = $map['length'];
         }
         if ($type === 'decimal' && isset($map['scale'])) {
             $type = 'float';
             $meta->custom['step'] = pow(10, -$map['scale']);
         }
     } elseif ($cm->hasAssociation($meta->name)) {
         $map = $cm->getAssociationMapping($meta->name);
         $type = $map['targetEntity'];
     }
     if (!$meta->type) {
         $meta->type = $type;
     }
 }
 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  */
 protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
 {
     $fields = array_diff($classMetadata->getFieldNames(), $classMetadata->getIdentifierFieldNames(), $this->getDeletedFields($classMetadata->name));
     foreach ($fields as $fieldName) {
         $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
         $entityMetadata->addFieldMetadata($fieldMetadata);
     }
 }
 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  */
 protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
 {
     $identifierFields = $classMetadata->getIdentifierFieldNames();
     foreach ($classMetadata->getFieldNames() as $fieldName) {
         if (in_array($fieldName, $identifierFields)) {
             continue;
         }
         $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
         $entityMetadata->addFieldMetadata($fieldMetadata);
     }
 }
 public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!$classMetadata->hasField($name)) {
         return NULL;
     }
     $mapping = $classMetadata->getFieldMapping($name);
     $controlName = empty($options['control']) ? $this->getControlByType($mapping['type']) : $options['control'];
     $control = ControlFactory::create($controlName, ['\\Nette\\Forms\\Controls\\BaseControl'], ControlFactory::TEXT_INPUT);
     if (empty($options['caption'])) {
         $control->caption = $configuration->getLabelingStrategy()->getControlLabel($name, $classMetadata);
     } else {
         $control->caption = $options['caption'];
     }
     return new ControlBuilder($control);
 }
Exemple #8
0
 public function getFieldsMetadata($class, $group = 'default')
 {
     $result = array();
     foreach ($this->ormMetadata->getFieldNames() as $name) {
         $mapping = $this->ormMetadata->getFieldMapping($name);
         //  $mapping['isAssociation']=false;
         $values = array('title' => $name, 'source' => true);
         if (isset($mapping['fieldName'])) {
             $values['field'] = $mapping['fieldName'];
             $values['id'] = $mapping['fieldName'];
         }
         if (isset($mapping['id']) && $mapping['id'] == 'id') {
             $values['primary'] = true;
         }
         switch ($mapping['type']) {
             case 'string':
             case 'text':
                 $values['type'] = 'text';
                 break;
             case 'integer':
             case 'smallint':
             case 'bigint':
             case 'float':
             case 'decimal':
                 $values['type'] = 'number';
                 break;
             case 'boolean':
                 $values['type'] = 'boolean';
                 break;
             case 'date':
                 $values['type'] = 'date';
                 break;
             case 'datetime':
                 $values['type'] = 'datetime';
                 break;
             case 'time':
                 $values['type'] = 'time';
                 break;
             case 'array':
             case 'object':
                 $values['type'] = 'array';
                 break;
         }
         $result[$name] = $values;
     }
     return $result;
 }
 /**
  * Truncate input text
  *
  * @param AbstractEntity $entity
  * @param string $field
  * @param
  * @return mixed
  */
 public function __invoke(AbstractEntity $entity, $field, ClassMetadata $metadata = null)
 {
     if (strpos($field, '.')) {
         list($Assoc, $field) = explode('.', $field, 2);
         if (!property_exists($entity, $Assoc)) {
             throw new \RuntimeException('Invalid Association found: ' . get_class($entity) . '#' . $Assoc);
         } else {
             if ($entity->{$Assoc} != null) {
                 return $this->__invoke($entity->{$Assoc}, $field);
             }
         }
         return null;
     } else {
         if (property_exists('__isInitialised__', $entity) && $entity->__isInitialized__) {
             // entity is an uninitialised proxy, lets load it
             $entity->load();
         }
         if (!property_exists($entity, $field)) {
             throw new \RuntimeException('Field "' . $field . '" not found in Entity: ' . get_class($entity));
         }
         $value = $entity->{$field};
         if ($metadata) {
             if ($column = $metadata->getFieldMapping($field)) {
                 switch (strtolower($column['type'])) {
                     case "money":
                         $value = $this->getView()->currencyFormat($value, 'GBP');
                         break;
                     case "datetime":
                         $value = $this->getView()->dateFormat($value, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
                         break;
                     case "date":
                         $value = $this->getView()->dateFormat($value, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
                         break;
                     case "time":
                         $value = $this->getView()->dateFormat($value, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT);
                         break;
                     case 'boolean':
                         $value = $value ? '<span class="true">yes</span>' : '<span class="false">no</span>';
                         break;
                 }
             }
         }
     }
     return $value;
 }
 /**
  * @param string $fieldName
  * @param ClassMetadata $classMetadata
  * @return ForestField
  */
 protected function createField($fieldName, ClassMetadata $classMetadata)
 {
     return new ForestField($fieldName, $classMetadata->getFieldMapping($fieldName)['type']);
 }
Exemple #11
0
 /**
  * @param ClassMetadata $metaData
  * @param $fieldName
  *
  * @return array
  *
  * @throws MappingException
  */
 protected function getSimpleTypeOptions(ClassMetadata $metaData, $fieldName)
 {
     $fieldInfo = $metaData->getFieldMapping($fieldName);
     $data = ['type' => $fieldInfo['type']];
     return $data;
 }
Exemple #12
0
 public function getPropertyDoctrineFieldMapping($property)
 {
     if ($this->orm_metadata->hasField($property)) {
         return $this->orm_metadata->getFieldMapping($property);
     }
 }
 /**
  * Returns database field mappings
  *
  * @param ClassMetadata $cm
  *
  * @return array
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 protected function getDatabaseFieldMappings(ClassMetadata $cm)
 {
     $fieldMappings = array();
     $fields = $cm->getFieldNames();
     foreach ($fields as $field) {
         $currentMapping = $cm->getFieldMapping($field);
         if ($currentMapping["fieldName"] == "id") {
             $currentMapping["fieldName"] = "@id";
             $currentMapping["type"] = "string";
         }
         $fieldMappings[] = array("name" => $currentMapping["fieldName"], "type" => $this->getExtJSFieldMapping($currentMapping["type"]));
     }
     return $fieldMappings;
 }
 /**
  * Get mappings.
  *
  * @param ClassMetadata $metadata
  * @param array         $fields
  *
  * @return array
  * @throws MappingException
  */
 protected function getMappings(ClassMetadata $metadata, array $fields)
 {
     $mappings = array();
     foreach ($fields as $field) {
         try {
             // Gets the mapping of a regular field
             $mappings[$field] = $metadata->getFieldMapping($field);
         } catch (MappingException $e) {
             // Gets the mapping of an association
             $mappings[$field] = $metadata->getAssociationMapping($field);
         }
     }
     return $mappings;
 }
 /**
  * @author Franlin Rivero Grcia <*****@*****.**>
  * @param string $key
  * @param type $fields
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param QueryBuilder $qb
  * @param type $asoc
  */
 public static function fieldFilter($class, &$filters, &$fields, &$asoc, &$meta, &$qb)
 {
     if (array_key_exists('select', $filters)) {
         $qb->select($filters['select']);
         unset($filters['select']);
     }
     $fTemp = json_decode(UtilRepository2::getContainer()->get('request')->get('filters'));
     if (is_array($fTemp)) {
         if (!(is_array($filters) && count($filters) > 0 || !is_array($filters) && $filters != null)) {
             $filters = $fTemp;
         }
     }
     if ($filters == null) {
         $filters = array();
     }
     if (!is_array($filters)) {
         $filters = array($filters);
     }
     foreach ($filters as $key => $value) {
         if ($value !== null && $value !== '') {
             if (in_array($key, $fields)) {
                 $map = $meta->getFieldMapping($key);
                 if ($map['type'] == 'string' || $map['type'] == 'text' || $map['type'] == 'varchar') {
                     if (UtilRepository2Config::$defaultStringComparer == 'like') {
                         $qb->andWhere("lower({$class}.{$key}) like :{$key}");
                         if (strpos($value, '%') === false) {
                             $qb->setParameter($key, "%" . strtolower($value) . "%");
                         } else {
                             $qb->setParameter($key, strtolower($value));
                         }
                     } else {
                         if (is_array($value)) {
                             $op = $value[0];
                             $qb->andWhere("lower({$class}.{$key}) {$op} :{$key}");
                             $qb->setParameter($key, strtolower($value[1]));
                         } else {
                             $qb->andWhere("lower({$class}.{$key}) = :{$key}");
                             $qb->setParameter($key, strtolower($value));
                         }
                     }
                 } else {
                     if (is_array($value)) {
                         $op = $value[0];
                         if ($op == 'in') {
                             $qb->andWhere("{$class}.{$key} {$op} (:{$key})");
                             $qb->setParameter($key, $value[1]);
                         } elseif ($op == 'is') {
                             $qb->andWhere("{$class}.{$key} is null");
                         } else {
                             $qb->andWhere("{$class}.{$key} {$op} :{$key}");
                             $qb->setParameter($key, strtolower($value[1]));
                         }
                     } else {
                         $qb->andWhere("{$class}.{$key} = :{$key}");
                         $qb->setParameter($key, $value);
                     }
                 }
             } elseif (in_array($key, $asoc)) {
                 if (is_array($value)) {
                     $op = $value[0];
                     if ($op == 'is') {
                         $qb->andWhere("{$class}.{$key} is null");
                     }
                 } else {
                     $qb->andWhere("{$class}.{$key} = :{$key}");
                     $qb->setParameter($key, $value);
                 }
             } else {
                 $op = UtilRepository2Config::$defaultForeignCompareOperator;
                 $param = str_replace(".", '', $key);
                 if (!is_array($value)) {
                     if ($op == 'like') {
                         $qb->andWhere("lower({$key}) {$op} :{$param}");
                     } else {
                         $qb->andWhere("{$key} {$op} :{$param}");
                     }
                     if ($op == 'like') {
                         if (strpos($value, '%') === false) {
                             $qb->setParameter($param, "%" . strtolower($value) . "%");
                         } else {
                             $qb->setParameter($param, strtolower($value));
                         }
                     } else {
                         $qb->setParameter($param, $value);
                     }
                 } else {
                     if ($value[0] == 'like') {
                         $qb->andWhere("lower({$key}) {$value['0']} :{$param}");
                     } elseif ($value[0] == 'in') {
                         $qb->andWhere("{$key} {$value['0']} (:{$param})");
                     } else {
                         $qb->andWhere("{$key} {$value['0']} :{$param}");
                     }
                     if ($value[0] == 'like') {
                         if (strpos($value[1], '%') === false) {
                             $qb->setParameter($param, "%" . strtolower($value[1]) . "%");
                         } else {
                             $qb->setParameter($param, strtolower($value[1]));
                         }
                     } else {
                         $qb->setParameter($param, $value[1]);
                     }
                 }
             }
         }
     }
     if (array_key_exists('start', $filters) && array_key_exists('limit', $filters) && $filters['start'] != null && $filters['limit'] != null) {
         $total = UtilRepository2::getTotalResult($qb, $class);
         $start = $filters['start'];
         $limit = $filters['limit'];
         $limit = $limit == -1 ? $total : $limit;
         unset($filters['start']);
         unset($filters['limit']);
         UtilRepository2::getSession()->set("total", $total);
         $qb->setFirstResult($start);
         $qb->setMaxResults($limit);
     } else {
         $start = UtilRepository2::getContainer()->get('request')->get('iDisplayStart');
         $size = UtilRepository2::getContainer()->get('request')->get('iDisplayLength');
         if ($start !== null && $size !== null) {
             $total = UtilRepository2::getTotalResult($qb, $class);
             $size = $size == -1 ? $total : $size;
             if ($start != null && $size != null) {
                 UtilRepository2::getSession()->set("total", $total);
                 $qb->setFirstResult($start);
                 $qb->setMaxResults($size);
             }
         }
     }
 }
 /**
  * @group DDC-944
  */
 public function testMappingNotFound()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException', "No mapping found for field 'foo' on class 'Doctrine\\Tests\\Models\\CMS\\CmsUser'.");
     $cm->getFieldMapping('foo');
 }
 /**
  * This method cleans empty translation entities.
  *
  * @param mixed $collection
  * @param ClassMetadata $classMetadata
  */
 private function cleanupCollection(&$collection, $classMetadata)
 {
     $notNullableStringProperties = array();
     $nullableStringProperties = array();
     $otherProperties = array();
     foreach ($classMetadata->getFieldNames() as $fieldName) {
         $fieldMapping = $classMetadata->getFieldMapping($fieldName);
         // skip id field
         if (isset($fieldMapping['id']) && $fieldMapping['id'] === true) {
             continue;
         }
         // skip language field
         if (in_array($fieldMapping['fieldName'], $this->autoRemoveIgnoreFields) || $fieldMapping['fieldName'] === $this->localePropertyPath) {
             continue;
         }
         if ($fieldMapping['nullable']) {
             if ($fieldMapping['type'] === 'string') {
                 $nullableStringProperties[] = $fieldMapping['fieldName'];
             } else {
                 $otherProperties[] = $fieldMapping['fieldName'];
             }
         } else {
             if ($fieldMapping['type'] === 'string') {
                 $notNullableStringProperties[] = $fieldMapping['fieldName'];
             } else {
                 $otherProperties[] = $fieldMapping['fieldName'];
             }
         }
     }
     $toRemove = array();
     foreach ($collection as $entity) {
         // entity is translation, i.e. $sitemapNodeTranslation
         $allNullableStringsAreNull = true;
         foreach ($nullableStringProperties as $pp) {
             // $pp is property path, i.e. 'short_description'
             // this calls something like $sitemapNodeTranslation->getShortDescription()
             $value = $this->propertyAccessor->getValue($entity, $pp);
             if (trim($value) === '') {
                 $this->propertyAccessor->setValue($entity, $pp, null);
             } else {
                 $allNullableStringsAreNull = false;
             }
         }
         $allNotNullableStringsAreNull = true;
         foreach ($notNullableStringProperties as $pp) {
             $value = $this->propertyAccessor->getValue($entity, $pp);
             if ($value !== null) {
                 if (trim($value) !== '') {
                     $allNotNullableStringsAreNull = false;
                 }
             } else {
                 $this->propertyAccessor->setValue($entity, $pp, '');
             }
         }
         $otherAreNull = true;
         foreach ($otherProperties as $pp) {
             $value = $this->propertyAccessor->getValue($entity, $pp);
             if ($value !== null) {
                 $otherAreNull = false;
             }
         }
         if ($allNullableStringsAreNull && $allNotNullableStringsAreNull && $otherAreNull) {
             $toRemove[] = $entity;
             if (null !== $this->objectManager && $this->objectManager->contains($entity)) {
                 $this->objectManager->remove($entity);
                 // Delete from db.
             }
         }
     }
     $this->removeFromCollection($collection, $toRemove);
 }
Exemple #18
0
 private function determineFromColumns(ClassMetadata $classMetadata)
 {
     $out = [];
     /** @var Column $column */
     foreach ($classMetadata->getFieldNames() as $fieldName) {
         $fieldMapping = [];
         try {
             $fieldMapping = $classMetadata->getFieldMapping($fieldName);
         } catch (MappingException $e) {
             $fieldMapping['type'] = 'undefined';
         }
         $columnName = $classMetadata->getColumnName($fieldName);
         $type = $classMetadata->getTypeOfField($fieldName);
         $isNullable = $classMetadata->isNullable($fieldName);
         if (strtolower($type) === 'enum') {
             $out[$columnName] = ['type' => IColumnStructure::ENUM];
             $enum = $fieldMapping['columnDefinition'];
             $options = str_getcsv(str_replace('enum(', '', substr($enum, 0, strlen($enum) - 1)), ',', "'");
             $out[$columnName]['values'] = [];
             foreach ($options as $option) {
                 $out[$columnName]['values'][] = $option;
             }
         } else {
             switch ($type) {
                 case Type::STRING:
                 case Type::TEXT:
                     $out[$columnName] = ['type' => IColumnStructure::TEXT];
                     break;
                 case Type::INTEGER:
                 case Type::FLOAT:
                 case Type::SMALLINT:
                 case Type::BIGINT:
                 case Type::DECIMAL:
                     $out[$columnName] = ['type' => IColumnStructure::NUMBER];
                     break;
                 case Type::DATETIME:
                 case Type::DATETIMETZ:
                 case Type::DATE:
                 case Type::TIME:
                     $out[$columnName] = ['type' => IColumnStructure::DATE];
                     break;
                 case Type::BOOLEAN:
                     $out[$columnName] = ['type' => IColumnStructure::BOOL];
                     break;
             }
         }
         if (isset($out[$columnName])) {
             $out[$columnName]['nullable'] = $isNullable;
         }
     }
     return $out;
 }
Exemple #19
0
 /**
  * Gets a list of all indexed fields
  *
  * @param ClassMetadata $metadata
  *
  * @return array [field name => field data-type, ...]
  */
 public function getIndexedFields(ClassMetadata $metadata)
 {
     $indexedColumns = [];
     $idFieldNames = $metadata->getIdentifierFieldNames();
     if (count($idFieldNames) > 0) {
         $indexedColumns[reset($idFieldNames)] = true;
     }
     if (isset($metadata->table['indexes'])) {
         foreach ($metadata->table['indexes'] as $index) {
             $firstFieldName = reset($index['columns']);
             if (!isset($indexedColumns[$firstFieldName])) {
                 $indexedColumns[$firstFieldName] = true;
             }
         }
     }
     $fields = [];
     $fieldNames = $metadata->getFieldNames();
     foreach ($fieldNames as $fieldName) {
         $mapping = $metadata->getFieldMapping($fieldName);
         $hasIndex = false;
         if (isset($mapping['unique']) && true === $mapping['unique']) {
             $hasIndex = true;
         } elseif (array_key_exists($mapping['columnName'], $indexedColumns)) {
             $hasIndex = true;
         }
         if ($hasIndex) {
             $fields[$fieldName] = $mapping['type'];
         }
     }
     return $fields;
 }
 /**
  * Get the date value to set on a timestampable field
  *
  * @param ORM\Mapping\ClassMetadata $classMetadata
  * @param string $field
  *
  * @return mixed
  */
 private function getDateValue(ORM\Mapping\ClassMetadata $classMetadata, $field)
 {
     $mapping = $classMetadata->getFieldMapping($field);
     if (isset($mapping['type']) && $mapping['type'] === 'integer') {
         return time();
     }
     if (isset($mapping['type']) && $mapping['type'] == 'zenddate') {
         return new \Zend_Date();
     }
     return \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
 }
 /**
  * Gather columns and fk constraints that are required for one part of relationship.
  *
  * @param array $joinColumns
  * @param \Doctrine\DBAL\Schema\Table $theJoinTable
  * @param ClassMetadata $class
  * @param \Doctrine\ORM\Mapping\AssociationMapping $mapping
  * @param array $primaryKeyColumns
  * @param array $uniqueConstraints
  */
 private function _gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$uniqueConstraints)
 {
     $localColumns = array();
     $foreignColumns = array();
     $fkOptions = array();
     foreach ($joinColumns as $joinColumn) {
         $columnName = $joinColumn['name'];
         $referencedFieldName = $class->getFieldName($joinColumn['referencedColumnName']);
         if (!$class->hasField($referencedFieldName)) {
             throw new \Doctrine\ORM\ORMException("Column name `" . $joinColumn['referencedColumnName'] . "` referenced for relation from " . $mapping['sourceEntity'] . " towards " . $mapping['targetEntity'] . " does not exist.");
         }
         $primaryKeyColumns[] = $columnName;
         $localColumns[] = $columnName;
         $foreignColumns[] = $joinColumn['referencedColumnName'];
         if (!$theJoinTable->hasColumn($joinColumn['name'])) {
             // Only add the column to the table if it does not exist already.
             // It might exist already if the foreign key is mapped into a regular
             // property as well.
             $fieldMapping = $class->getFieldMapping($referencedFieldName);
             $columnDef = null;
             if (isset($joinColumn['columnDefinition'])) {
                 $columnDef = $joinColumn['columnDefinition'];
             } else {
                 if (isset($fieldMapping['columnDefinition'])) {
                     $columnDef = $fieldMapping['columnDefinition'];
                 }
             }
             $columnOptions = array('notnull' => false, 'columnDefinition' => $columnDef);
             if (isset($joinColumn['nullable'])) {
                 $columnOptions['notnull'] = !$joinColumn['nullable'];
             }
             if ($fieldMapping['type'] == "string") {
                 $columnOptions['length'] = $fieldMapping['length'];
             } else {
                 if ($fieldMapping['type'] == "decimal") {
                     $columnOptions['scale'] = $fieldMapping['scale'];
                     $columnOptions['precision'] = $fieldMapping['precision'];
                 }
             }
             $theJoinTable->addColumn($columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), $columnOptions);
         }
         if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
             $uniqueConstraints[] = array('columns' => array($columnName));
         }
         if (isset($joinColumn['onUpdate'])) {
             $fkOptions['onUpdate'] = $joinColumn['onUpdate'];
         }
         if (isset($joinColumn['onDelete'])) {
             $fkOptions['onDelete'] = $joinColumn['onDelete'];
         }
     }
     $theJoinTable->addUnnamedForeignKeyConstraint($class->getTableName(), $localColumns, $foreignColumns, $fkOptions);
 }
 /**
  * Transform a class entityMetadata object to a more user-friendly array
  *
  * @param ClassMetadata $metaData
  * @return array
  * @throws \Exception
  */
 public function parseMetaDataToFieldArray(ClassMetadata $metaData)
 {
     $columns = array();
     foreach (array_keys($metaData->reflFields) as $fieldName) {
         if (array_key_exists($fieldName, $metaData->fieldMappings)) {
             $fieldData = $metaData->getFieldMapping($fieldName);
             $columns[$fieldName] = $fieldData;
         } elseif (array_key_exists($fieldName, $metaData->associationMappings)) {
             $fieldData = $metaData->getAssociationMapping($fieldName);
             $fieldData['associationType'] = $fieldData['type'];
             $fieldData['type'] = 'association';
             $columns[$fieldName] = $fieldData;
         } else {
             throw new \Exception(sprintf('Can\'t map %s in the %s Entity', $fieldName, $metaData->name));
         }
     }
     return $columns;
 }
 /**
  * @group DDC-944
  */
 public function testMappingNotFound()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $this->setExpectedException('Doctrine\\ORM\\Mapping\\MappingException', "No mapping found for field 'foo' on class 'Doctrine\\Tests\\Models\\CMS\\CmsUser'.");
     $cm->getFieldMapping('foo');
 }
 /**
  * Returns database field mappings.
  *
  * @param ClassMetadata $cm
  *
  * @throws \Doctrine\ORM\Mapping\MappingException
  *
  * @return array
  */
 protected function getDatabaseFieldMappings(ClassMetadata $cm)
 {
     $fieldMappings = [];
     $fields = $cm->getFieldNames();
     foreach ($fields as $field) {
         $currentMapping = $cm->getFieldMapping($field);
         $asserts = $this->getExtJSAssertMappings($cm, $field);
         if ($currentMapping['fieldName'] == 'id') {
             $currentMapping['fieldName'] = '@id';
             $currentMapping['type'] = 'string';
         }
         $fieldMappings[] = ['name' => $currentMapping['fieldName'], 'type' => $this->getExtJSFieldMapping($currentMapping['type']), 'validators' => json_encode($asserts), 'persist' => $this->allowPersist($cm, $field)];
     }
     return $fieldMappings;
 }