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);
|
$identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||||
|
|
||||||
foreach ($this->class->identifier as $idField) {
|
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];
|
$params[] = $identifier[$idField];
|
||||||
$where[] = $this->class->associationMappings[$idField]['joinColumns'][0]['name'];
|
$where[] = $this->class->associationMappings[$idField]['joinColumns'][0]['name'];
|
||||||
@ -432,12 +439,6 @@ class BasicEntityPersister
|
|||||||
throw ORMException::unrecognizedField($targetMapping->identifier[0]);
|
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) {
|
if ($versioned) {
|
||||||
@ -586,7 +587,15 @@ class BasicEntityPersister
|
|||||||
|
|
||||||
$newVal = $change[1];
|
$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];
|
$assoc = $this->class->associationMappings[$field];
|
||||||
|
|
||||||
// Only owning side of x-1 associations can have a FK column.
|
// 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);
|
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
|
||||||
|
|
||||||
$this->quotedColumns[$sourceColumn] = $quotedColumn;
|
$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);
|
$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;
|
return $result;
|
||||||
@ -747,7 +757,10 @@ class BasicEntityPersister
|
|||||||
if ($targetEntity !== null && $isInverseSingleValued) {
|
if ($targetEntity !== null && $isInverseSingleValued) {
|
||||||
$targetClass->reflFields[$assoc['inversedBy']]->setValue($targetEntity, $sourceEntity);
|
$targetClass->reflFields[$assoc['inversedBy']]->setValue($targetEntity, $sourceEntity);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
return $targetEntity;
|
||||||
|
}
|
||||||
|
|
||||||
$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
|
$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
|
||||||
$owningAssoc = $targetClass->getAssociationMapping($assoc['mappedBy']);
|
$owningAssoc = $targetClass->getAssociationMapping($assoc['mappedBy']);
|
||||||
|
|
||||||
@ -772,7 +785,6 @@ class BasicEntityPersister
|
|||||||
if ($targetEntity !== null) {
|
if ($targetEntity !== null) {
|
||||||
$targetClass->setFieldValue($targetEntity, $assoc['mappedBy'], $sourceEntity);
|
$targetClass->setFieldValue($targetEntity, $assoc['mappedBy'], $sourceEntity);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $targetEntity;
|
return $targetEntity;
|
||||||
}
|
}
|
||||||
@ -974,7 +986,6 @@ class BasicEntityPersister
|
|||||||
|
|
||||||
foreach ($joinColumns as $joinColumn) {
|
foreach ($joinColumns as $joinColumn) {
|
||||||
|
|
||||||
$relationKeyColumn = $joinColumn['name'];
|
|
||||||
$sourceKeyColumn = $joinColumn['referencedColumnName'];
|
$sourceKeyColumn = $joinColumn['referencedColumnName'];
|
||||||
$quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
|
$quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user