Second round of refactorings on BasicEntityPersister
This commit is contained in:
parent
04e1838c92
commit
827153624c
@ -413,7 +413,14 @@ class BasicEntityPersister
|
||||
$identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||
|
||||
foreach ($this->class->identifier as $idField) {
|
||||
if (isset($this->class->associationMappings[$idField])) {
|
||||
if ( ! isset($this->class->associationMappings[$idField])) {
|
||||
|
||||
$params[] = $identifier[$idField];
|
||||
$types[] = $this->class->fieldMappings[$idField]['type'];
|
||||
$where[] = $this->quoteStrategy->getColumnName($idField, $this->class, $this->platform);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$params[] = $identifier[$idField];
|
||||
$where[] = $this->class->associationMappings[$idField]['joinColumns'][0]['name'];
|
||||
@ -432,12 +439,6 @@ class BasicEntityPersister
|
||||
throw ORMException::unrecognizedField($targetMapping->identifier[0]);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$params[] = $identifier[$idField];
|
||||
$types[] = $this->class->fieldMappings[$idField]['type'];
|
||||
$where[] = $this->quoteStrategy->getColumnName($idField, $this->class, $this->platform);
|
||||
}
|
||||
|
||||
if ($versioned) {
|
||||
@ -586,7 +587,15 @@ class BasicEntityPersister
|
||||
|
||||
$newVal = $change[1];
|
||||
|
||||
if (isset($this->class->associationMappings[$field])) {
|
||||
if ( ! isset($this->class->associationMappings[$field])) {
|
||||
|
||||
$columnName = $this->class->columnNames[$field];
|
||||
$this->columnTypes[$columnName] = $this->class->fieldMappings[$field]['type'];
|
||||
$result[$this->getOwningTable($field)][$columnName] = $newVal;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$assoc = $this->class->associationMappings[$field];
|
||||
|
||||
// Only owning side of x-1 associations can have a FK column.
|
||||
@ -621,24 +630,25 @@ class BasicEntityPersister
|
||||
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
|
||||
|
||||
$this->quotedColumns[$sourceColumn] = $quotedColumn;
|
||||
|
||||
if ($newVal === null) {
|
||||
$result[$owningTable][$sourceColumn] = null;
|
||||
} else if ($targetClass->containsForeignIdentifier) {
|
||||
$result[$owningTable][$sourceColumn] = $newValId[$targetClass->getFieldForColumn($targetColumn)];
|
||||
} else {
|
||||
$result[$owningTable][$sourceColumn] = $newValId[$targetClass->fieldNames[$targetColumn]];
|
||||
}
|
||||
|
||||
$this->columnTypes[$sourceColumn] = $targetClass->getTypeOfColumn($targetColumn);
|
||||
|
||||
switch (true) {
|
||||
case $newVal === null:
|
||||
$value = null;
|
||||
break;
|
||||
|
||||
case $targetClass->containsForeignIdentifier:
|
||||
$value = $newValId[$targetClass->getFieldForColumn($targetColumn)];
|
||||
break;
|
||||
|
||||
default:
|
||||
$value = $newValId[$targetClass->fieldNames[$targetColumn]];
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
$result[$owningTable][$sourceColumn] = $value;
|
||||
}
|
||||
|
||||
$columnName = $this->class->columnNames[$field];
|
||||
$this->columnTypes[$columnName] = $this->class->fieldMappings[$field]['type'];
|
||||
$result[$this->getOwningTable($field)][$columnName] = $newVal;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -747,7 +757,10 @@ class BasicEntityPersister
|
||||
if ($targetEntity !== null && $isInverseSingleValued) {
|
||||
$targetClass->reflFields[$assoc['inversedBy']]->setValue($targetEntity, $sourceEntity);
|
||||
}
|
||||
} else {
|
||||
|
||||
return $targetEntity;
|
||||
}
|
||||
|
||||
$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
|
||||
$owningAssoc = $targetClass->getAssociationMapping($assoc['mappedBy']);
|
||||
|
||||
@ -772,7 +785,6 @@ class BasicEntityPersister
|
||||
if ($targetEntity !== null) {
|
||||
$targetClass->setFieldValue($targetEntity, $assoc['mappedBy'], $sourceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
return $targetEntity;
|
||||
}
|
||||
@ -974,7 +986,6 @@ class BasicEntityPersister
|
||||
|
||||
foreach ($joinColumns as $joinColumn) {
|
||||
|
||||
$relationKeyColumn = $joinColumn['name'];
|
||||
$sourceKeyColumn = $joinColumn['referencedColumnName'];
|
||||
$quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user