Get the target field.

@param $meta
@param $parentMeta
@param $value

@return string
428286
private function getTargetField($meta, $parentMeta, $value)
    {
        if (count($parentMeta->parentClasses) > 0) {
            foreach ($parentMeta->parentClasses as $classe) {
                $associationsByTargetClass = $meta->getAssociationsByTargetClass($classe);
                if (count($associationsByTargetClass) > 0) {
                    $parentTable = lcfirst(substr($classe, strrpos($classe, strpos($classe, '\\') !== false ? '\\' : '/') + 1));
                    $field = $this->searchAssociationField($associationsByTargetClass, $parentTable, $value);
                    if ($field) {
                        return $field;
                    }
                }
            }
        }
        $associationsByTargetClass = $meta->getAssociationsByTargetClass($parentMeta->getName());
        $field = $this->searchAssociationField($associationsByTargetClass, lcfirst($parentMeta->getTableName()), $value);
        if ($field) {
            return $field;
        }

        return $meta->getIdentifierColumnNames()[0];
    }
685062
public function getMeta($name)
    {
        $node = $this->filterXPath('descendant-or-self::meta[@name = \'' . $name . '\']')->getNode(0);
        if ($node instanceof \DOMElement) {
            return $node->getAttribute('content');
        } else {
            return null;
        }
    }
712189
public function transformOutput(FieldMetadata $metadata, $value) {
        if($value === true || $value === 1) {
            return 'true';
        } else {
            if($value === false || $value === 0) {
                return 'false';
            } else {
                return 'unknown';
            }
        }
    }
780371
private function setQueryField($meta, $value, $alias)
    {
        $campo = $this->getFullFieldName($value, $alias);

        if ($meta->isSingleValuedAssociation($value) && $value != $alias) {
            $targetField = $meta->getAssociationMapping($value)['joinColumns'][0]['referencedColumnName'];
            $alias = $alias == self::DEFAULT_TABLE_ALIAS ? substr($campo, strpos($campo, '.') + 1) : $alias.'_'.$targetField;
            $campo = 'IDENTITY('.$campo.') '.$alias;
        } elseif ($this->position > 0) {
            $campo = '('.$campo.') AS '.$alias.'_'.$value;
        }
        // acrescenta o campo ao select
        $this->queryFields[] = $campo;
    }
623616
private function getFieldFilter(ClassMetadata $metadata, array $fields)
    {
        /* @var \Doctrine\ORM\Mapping\ClassMetadata $metadata */
        $filters = array();
        foreach ($fields as $field) {
            $fieldName = $this->getFieldName($metadata, $field);
            try {
                $filters[] = $metadata->getFieldMapping($fieldName);
            } catch (\Exception $ex) {
                $mapping = $metadata->getAssociationMapping($fieldName);
                $associationMatadata = $this->entityManager->getClassMetadata($mapping['targetEntity']);
                $associationFields = $associationMatadata->getFieldNames();
                $associationIdentifier = $associationMatadata->getIdentifierFieldNames();
                $associationFields = array_values(array_filter(
                    $associationFields,
                    function ($value) use ($associationIdentifier) {
                        return !in_array($value, $associationIdentifier);
                    }
                ));
                if ($associationFields) {
                    $filters[] = array_merge(array(
                        'join' => true,
                        'join_field' => $fieldName,
                        'join_alias' => $this->getAlias(),
                    ), $associationMatadata->getFieldMapping($associationFields[0]));
                }
            }
        }

        return $filters;
    }
687940
protected function __getMetaString()
    {
        $strOutput = "";

        foreach ($this->__meta as $key => $value) {
            if (! in_array($key, array_merge($this->__reservedmeta, $this->__fieldmeta))) {
                $strOutput .= " {$key}=\"{$value}\"";
            }
        }

        return $strOutput;
    }
942547
protected function findOneByMetaSetAndTarget(MetaSetInterface $metaSet, $target)
    {
        $metaDatas = $this->findByMetaSetAndTarget($metaSet, $target);

        if (!count($metaDatas)) {
            return null;
        }

        return current($metaDatas);
    }
472598
protected function searchForMetaValue( $meta_key, array $postmeta ) {

		if ( empty( $postmeta ) ) {
			return '';
		}

		foreach ( $postmeta as $meta ) {
			// prefer this value, if it's set
			if ( $meta_key === $meta['key'] ) {
				$meta_val = $meta['value'];
				if ( is_serialized( $meta_val ) ) {
					$meta_val = unserialize( $meta_val ); // @codingStandardsIgnoreLine
					if ( is_object( $meta_val ) ) {
						$meta_val = ''; // Hack attempt?
					}
				}
				return $meta_val;
			}
		}

		return '';
	}
459859
public function getFieldsFromMetadata(ClassMetadata $metadata)
    {
        /* @var \Doctrine\ORM\Mapping\ClassMetadataInfo|\Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo $metadata */
        $fields = (array) $metadata->getFieldNames();

        $exclude = array(
            'createdAt', 'created_at', 'createdBy', 'created_by',
            'updatedAt', 'updated_at', 'updatedBy', 'updated_by',
        );

        // Remove the primary key field if it's not managed manually
        $fields = array_diff($fields, $metadata->getIdentifier());

        foreach ($metadata->associationMappings as $fieldName => $relation) {
            if ($relation['type'] !== 4) {
                $fields[] = $fieldName;
            }
        }

        return array_values(array_diff($fields, $exclude));
    }
119682
public function getFieldMeta($property = null, $fallbackValue = "")
    {
        if (is_null($property)) {
            $varReturn = $this->__fieldmeta;
        } elseif (isset($this->__fieldmeta[$property])
            && !is_null($this->__fieldmeta[$property])
        ) {
            $varReturn = $this->__fieldmeta[$property];
        } else {
            $varReturn = $fallbackValue;
        }

        return $varReturn;
    }
290186
public function getMeta($id, $name = null, $field = 'value') {
        if ($name) {
            $values = $this->get([$this->metaIdField => intval($id), $this->metaNameField => $name])->get($field);
        } else {
            $values = $this->findAll([$this->metaIdField => intval($id)], [
                $field,
                $this->metaNameField
            ])->toArray($field, $this->metaNameField);
        }

        return $values;
    }
690729
public function transformInput(FieldMetadata $metadata, $value) {
        $isInt = true;
        foreach(array_keys($metadata->options) as $key => $notUsed) {
            if(!is_integer($key)) {
                $isInt = false;
            }
        }

        if($isInt) {
            return (int)$value;
        } else {
            return $value;
        }
    }
1088165
private function getTypes($field, $value, ClassMetadata $class)
    {
        $property = $class->getProperty($field);
        $types    = [];

        switch (true) {
            case $property instanceof FieldMetadata:
                $types = array_merge($types, [$property->getType()]);
                break;

            case $property instanceof AssociationMetadata:
                $class = $this->em->getClassMetadata($property->getTargetEntity());

                if (! $property->isOwningSide()) {
                    $property = $class->getProperty($property->getMappedBy());
                    $class    = $this->em->getClassMetadata($property->getTargetEntity());
                }

                $joinColumns = $property instanceof ManyToManyAssociationMetadata
                    ? $property->getJoinTable()->getInverseJoinColumns()
                    : $property->getJoinColumns();

                foreach ($joinColumns as $joinColumn) {
                    /** @var JoinColumnMetadata $joinColumn */
                    $referencedColumnName = $joinColumn->getReferencedColumnName();

                    if (! $joinColumn->getType()) {
                        $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $class, $this->em));
                    }

                    $types[] = $joinColumn->getType();
                }

                break;

            default:
                $types[] = null;
                break;
        }

        if (is_array($value)) {
            return array_map(static function ($type) {
                return $type->getBindingType() + Connection::ARRAY_PARAM_OFFSET;
            }, $types);
        }

        return $types;
    }
801208
public function getAttributeDbValue(AttributeMetadata $attrMeta, $value)
    {
        // Handle data type conversion, if needed.
        if ('date' === $attrMeta->dataType && $value instanceof \DateTime) {
            return new \MongoDate($value->getTimestamp(), $value->format('u'));
        }
        if ('array' === $attrMeta->dataType && empty($value)) {
            return;
        }
        if ('object' === $attrMeta->dataType) {
            $array = (array) $value;
            return empty($array) ? null : $value;
        }
        return $value;
    }
155150
protected function normalizeProperty($value, $name, $format = null, array $context = array())
    {
        /** @var ClassMetadata $meta */
        $meta = $context['entityMeta'];

        if ($meta->hasField($name)) {
            return $value;
        }

        if (isset($meta->embeddedClasses[$name])) {
            return parent::normalize($value, $format, $context);
        }

        switch ($meta->associationMappings[$name]['type']) {
            case ClassMetadata::ONE_TO_ONE:
            case ClassMetadata::MANY_TO_ONE:
                return $this->normalizeAssociation($value, $name, $format, $context);

            case ClassMetadata::ONE_TO_MANY:
            case ClassMetadata::MANY_TO_MANY:
                return $this->normalizeCollection($value, $name, $format, $context);
        }
    }
1149335
private function addGraphLink($sourceIndex, $value, array $meta)
    {
        $targetIndex = $this->getTargetIndex($value, $meta);
        $type = $this->getType($value);
        $this->graph['links'][] = ['source' => $sourceIndex, 'target' => $targetIndex, 'type' => $type];

        return $targetIndex;
    }
581789
public function deleteMeta($key, $value = null)
    {
        return $value
            ? $this->meta()->where('key', $key)->where('value', $value)->delete()
            : $this->meta()->where('key', $key)->delete();
    }