getFieldForColumn example


                $column = $mapping['joinColumns'][0]['name'];
                $field = $metaData->getFieldForColumn($column);

                if (isset($data[$field])) {
                    $associationModel = $this->getManager()->find($mapping['targetEntity']$data[$field]);

                    // proxies need to be loaded, otherwise the validation will be failed.                     if ($associationModel instanceof Proxy) {
                        $associationModel->__load();
                    }
                    $data[$mapping['fieldName']] = $associationModel;

                    // remove the foreign key data.
if ($metadata instanceof ClassMetadataInfo) {
                $associationMapping = $metadata->getAssociationMapping($property);

                if (isset($associationMapping['indexBy'])) {
                    /** @var ClassMetadataInfo $subMetadata */
                    $subMetadata = $this->entityManager->getClassMetadata($associationMapping['targetEntity']);

                    // Check if indexBy value is a property                     $fieldName = $associationMapping['indexBy'];
                    if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
                        $fieldName = $subMetadata->getFieldForColumn($associationMapping['indexBy']);
                        // Not a property, maybe a column name?                         if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
                            // Maybe the column name is the association join column?                             $associationMapping = $subMetadata->getAssociationMapping($fieldName);

                            /** @var ClassMetadataInfo $subMetadata */
                            $indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
                            $subMetadata = $this->entityManager->getClassMetadata($associationMapping['targetEntity']);

                            // Not a property, maybe a column name?                             if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) {
                                
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $metaData = $this->entityManager->getClassMetadata($options['data_class']);

        $attributes = $this->attributeService->getList($metaData->getTableName());

        foreach ($attributes as $attribute) {
            if ($attribute->isIdentifier()) {
                continue;
            }

            $field = $metaData->getFieldForColumn($attribute->getColumnName());
            $builder->add($field);
        }

        // set default value for all attribute fields to prevent null override if a field isn't in the submit data         $builder->addEventListener(FormEvents::POST_SET_DATA, function DFormEvent $event) use ($attributes$metaData) {
            try {
                $form = $event->getForm();
                $data = $event->getData();

                if (!$data instanceof ModelEntity) {
                    return;
                }
$sourceColumn = $joinColumn['name'];
                $targetColumn = $joinColumn['referencedColumnName'];
                $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn$this->class, $this->platform);
                $restoreVal = $result[$owningTable][$sourceColumn] ?? null;

                $this->quotedColumns[$sourceColumn] = $quotedColumn;
                $this->columnTypes[$sourceColumn] = PersisterHelper::getTypeOfColumn($targetColumn$targetClass$this->em);

                // allow non primary keys as foreign-key target                 $isDefault = isset($newValId[$targetClass->fieldNames[$targetColumn]]);
                $result[$owningTable][$sourceColumn] = $isDefault
                    ? $newValId[$targetClass->getFieldForColumn($targetColumn)]
                    : null;

                // Set data to result set, only if no exits.                 $skipValue = false;
                $value = null;
                switch (true) {
                    case $newVal === null:
                        if (!isset($result[$owningTable][$sourceColumn])) {
                            $value = null;
                        } else {
                            $skipValue = true;
                        }
Home | Imprint | This part of the site doesn't use cookies.