Index: Classes/Persistence/Backend.php =================================================================== --- Classes/Persistence/Backend.php (Revision 2531) +++ Classes/Persistence/Backend.php (Arbeitskopie) @@ -523,12 +523,9 @@ } } - if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { - $this->deleteAllRelationsFromRelationtable($parentObject, $propertyName); - } - $currentUids = array(); $sortingPosition = 1; + $cleanPropertyValue = $parentObject->_getCleanProperty($propertyName); foreach ($objectStorage as $object) { if ($object->_isNew()) { if ($object instanceof Tx_Extbase_DomainObject_AbstractEntity) { @@ -537,18 +534,21 @@ $this->persistValueObject($object, $sortingPosition); } } + // object newly added to the relation + if (!$cleanPropertyValue->contains($object)) { + $this->attachObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition); + } $currentUids[] = $object->getUid(); - $this->attachObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition); $sortingPosition++; } - + if ($columnMap->getParentKeyFieldName() === NULL) { $row[$columnMap->getColumnName()] = implode(',', $currentUids); } else { $row[$columnMap->getColumnName()] = $this->dataMapper->countRelated($parentObject, $propertyName); } } - + /** * Returns the current field value of the given object property from the storage backend. *