Set identifier from association.

@param string|array       $association
@param string             $key
@param int                $i
@param ClassMetadata|null $metadata

@return $this

@throws \Exception
515223
private function setIdentifierFromAssociation($association, $key = '', $i = 0, $metadata = null)
    {
        if (null === $metadata) {
            $metadata = $this->metadata;
        }

        if (is_string($association)) {
            $targetEntityClass = $metadata->getAssociationTargetClass($association);
            $targetMetadata = $this->getMetadata($targetEntityClass);
            $this->selectColumns[$association][] = $this->getIdentifier($targetMetadata);
        }

        if (is_array($association) && array_key_exists($i, $association)) {
            $column = $association[$i];
            $count = count($association) - 1;
            if (true === $metadata->hasAssociation($column)) {
                $targetEntityClass = $metadata->getAssociationTargetClass($column);
                $targetMetadata = $this->getMetadata($targetEntityClass);
                if ($count == $i) {
                    $this->selectColumns[$key][] = $this->getIdentifier($targetMetadata);
                } else {
                    ++$i;
                    $this->setIdentifierFromAssociation($association, $key, $i, $targetMetadata);
                }
            }
        }

        return $this;
    }
676242
protected function createAssociation(ClassMetadataBuilder $builder, $relation, $entity)
    {
        return $this->builder->createManyToMany($relation, $entity);
    }
53667
def add_association(name, type, metadata={})
      associations << (metadata || {}).merge(:name => name.to_sym, :type => type.to_sym)
    end
223343
public function addAssociation($isCollection, $field, $targetMultiModel, array $compatible = array(), array $references = array())
    {
        $mapping = new AssociationDefinition($field, $targetMultiModel, $isCollection);
        $mapping->setCompatible($compatible);
        $mapping->setReferences($references);

        $this->associationMappings[$field] = $mapping;

        return $mapping;
    }
1277276
private function getAssociationFromServer($associationKey)
    {
        $association = $this->redis->get($associationKey);
        return $association ? unserialize($association) : null;
    }
132835
private function createManyToOneRelation(array &$data, $key)
    {
        $uid = isset($data[$key]) ? (int)$data[$key] : 0;

        $data[$key] = ($uid > 0)
            ? \Tx_Oelib_MapperRegistry::get($this->relations[$key])->find($uid)
            : null;
    }
987339
public function add(CollectionInstanceInterface $instance, $key = null)
    {
        if (!empty($key)) {
            $this->collection[$key] = $instance;
        } else {
            $this->collection[] = $instance;
        }
        return $this;
    }
144506
public function addMeta($key, $data = null)
    {
        if (is_array($key)) {
            $this->meta += $key;
        } else {
            $this->meta[$key] = $data;
        }

        return $this;
    }
380982
protected function createAssociation(ClassMetadataBuilder $builder, $relation, $entity)
    {
        return $this->builder->createManyToOne(
            $relation,
            $entity
        );
    }
1233911
private function computeAssociationChanges(AssociationMetadata $association, $value)
    {
        if ($value instanceof GhostObjectInterface && ! $value->isProxyInitialized()) {
            return;
        }

        if ($value instanceof PersistentCollection && $value->isDirty()) {
            $coid = spl_object_id($value);

            $this->collectionUpdates[$coid]  = $value;
            $this->visitedCollections[$coid] = $value;
        }

        // Look through the entities, and in any of their associations,
        // for transient (new) entities, recursively. ("Persistence by reachability")
        // Unwrap. Uninitialized collections will simply be empty.
        $unwrappedValue = $association instanceof ToOneAssociationMetadata ? [$value] : $value->unwrap();
        $targetEntity   = $association->getTargetEntity();
        $targetClass    = $this->em->getClassMetadata($targetEntity);

        foreach ($unwrappedValue as $key => $entry) {
            if (! ($entry instanceof $targetEntity)) {
                throw ORMInvalidArgumentException::invalidAssociation($targetClass, $association, $entry);
            }

            $state = $this->getEntityState($entry, self::STATE_NEW);

            if (! ($entry instanceof $targetEntity)) {
                throw UnexpectedAssociationValue::create(
                    $association->getSourceEntity(),
                    $association->getName(),
                    get_class($entry),
                    $targetEntity
                );
            }

            switch ($state) {
                case self::STATE_NEW:
                    if (! in_array('persist', $association->getCascade(), true)) {
                        $this->nonCascadedNewDetectedEntities[spl_object_id($entry)] = [$association, $entry];

                        break;
                    }

                    $this->persistNew($targetClass, $entry);
                    $this->computeChangeSet($targetClass, $entry);

                    break;

                case self::STATE_REMOVED:
                    // Consume the $value as array (it's either an array or an ArrayAccess)
                    // and remove the element from Collection.
                    if ($association instanceof ToManyAssociationMetadata) {
                        unset($value[$key]);
                    }
                    break;

                case self::STATE_DETACHED:
                    // Can actually not happen right now as we assume STATE_NEW,
                    // so the exception will be raised from the DBAL layer (constraint violation).
                    throw ORMInvalidArgumentException::detachedEntityFoundThroughRelationship($association, $entry);
                    break;

                default:
                    // MANAGED associated entities are already taken into account
                    // during changeset calculation anyway, since they are in the identity map.
            }
        }
    }
307389
public function setAuthKey($key)
    {
        $authKeyAttribute = $this->authKeyAttribute;
        return (is_string($authKeyAttribute) && !empty($authKeyAttribute)) ? $this->$authKeyAttribute = $key : null;
    }
851543
public function validateAssociations() : void
    {
        array_map(
            function (Property $property) {
                if (! ($property instanceof AssociationMetadata)) {
                    return;
                }

                $targetEntity = $property->getTargetEntity();

                if (! class_exists($targetEntity)) {
                    throw MappingException::invalidTargetEntityClass($targetEntity, $this->className, $property->getName());
                }
            },
            $this->declaredProperties
        );
    }
797052
public function add_metadata_file(cc_i_metadata_file $met, $identifier, $filename) {

        if (empty($met) || empty($identifier) || empty($filename)) {
            throw new Exception('Try to add a metadata file with nulls values given!');
        }

        $metanode = $this->node("//imscc:resource".
            "[@identifier='".
            $identifier.
            "']/imscc:file".
            "[@href='".
            $filename.
            "']");

        $nspaces = $this->activemanifest->get_cc_namespaces();
        $dnode   = $this->doc->createElementNS($nspaces['imscc'], "metadata");

        $metanode->appendChild($dnode);

        $this->activemanifest->create_metadata_file_node($met, $this->doc, $dnode);
    }
202014
private function createEntityCacheKey(ClassMetadata $classMetadata, array $data, $revision)
    {
        $keyParts = array();

        foreach ($classMetadata->getIdentifierFieldNames() as $name) {
            if ($classMetadata->hasAssociation($name)) {
                if ($classMetadata->isSingleValuedAssociation($name)) {
                    $name = $classMetadata->getSingleAssociationJoinColumnName($name);
                } else {
                    // Doctrine should throw a mapping exception if an identifier
                    // that is an association is not single valued, but just in case.
                    throw new \RuntimeException('Multiple valued association identifiers not supported');
                }
            }
            $keyParts[] = $data[$name];
        }

        return $classMetadata->name . '_' . implode('_', $keyParts) . '_' . $revision;
    }
387828
protected function normalizeAssociation($association, $name, $format = null, array $context = array())
    {
        if ($association === null) {
            return;
        }

        $hint = $this->getHintFromObject($association);
        $ids = $this->getIdentifierFromObject($association);
        $id = $this->getIdentifiersAsString($ids);
        $data = array_merge($hint, $ids);
        $objectId = current($hint).'#'.$id;

        if (isset($context['@references'][$objectId])) {
            return $data;
        }

        $context['@references'][$objectId] = false;
        if ($association instanceof Proxy and !$association->__isInitialized()) {
            return $data;
        }

        $normalized = $this->serializer->normalize($association, $format, $context);

        $context['@references'][$objectId] = $normalized;

        return $data;
    }
1017308
protected function setSingleFieldColumnInfo(array &$association, $fieldName) {
        $fieldName = Container::camelize($fieldName);

        if (!$this->metadata->hasField(lcfirst($fieldName))) {
            throw new Exception(
                "Field '$fieldName' not found.)",
                '404'
            );
        }

        $association['fieldName'] = $fieldName;
        $association['entityName'] = $this->tableName;
        $association['fullName'] = $this->tableName . '.' . lcfirst($fieldName);
    }
35290
public void setAssociationIds(java.util.Collection<String> associationIds) {
        if (associationIds == null) {
            this.associationIds = null;
            return;
        }

        this.associationIds = new com.amazonaws.internal.SdkInternalList<String>(associationIds);
    }