private function getUniqueAndRequiredAssociations(ClassMetadata $meta, $entity) { $associations = array(); foreach ($meta->getAssociationNames() as $associationName) { $mapping = $meta->getAssociationMapping($associationName); if (!empty($mapping['id']) && $meta->usesIdGenerator()) { // autogenerated id continue; } if (!($mapping['type'] & ClassMetadata::TO_ONE)) { // is not to one relation continue; } if (empty($mapping['isOwningSide'])) { // is not owning side continue; } foreach ($mapping['joinColumns'] as $joinColumn) { if (!empty($joinColumn['nullable']) && empty($joinColumn['unique'])) { // is nullable and is not unique continue; } $targetColumn = $joinColumn['referencedColumnName']; $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); $newVal = $meta->getFieldValue($entity, $associationName); if ($newVal !== NULL) { $newValId = $this->uow->getEntityIdentifier($newVal); } switch (TRUE) { case $newVal === NULL: $value = NULL; break; case $targetClass->containsForeignIdentifier: $value = $newValId[$targetClass->getFieldForColumn($targetColumn)]; break; default: $value = $newValId[$targetClass->fieldNames[$targetColumn]]; break; } $sourceColumn = $joinColumn['name']; $quotedColumn = $this->quotes->getJoinColumnName($joinColumn, $meta, $this->platform); $associations[$sourceColumn]['value'] = $value; $associations[$sourceColumn]['quotedColumn'] = $quotedColumn; $associations[$sourceColumn]['type'] = $targetClass->getTypeOfColumn($targetColumn); } } return $associations; }