diff --git a/composer.json b/composer.json index 1321d201..fec7e9b2 100755 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ ], "require": { "php": "^8.1", - "silverstripe/framework": "^5", + "silverstripe/framework": "^5.2", "symfony/cache": "^6.1", "silverstripe/vendor-plugin": "^2" }, @@ -44,4 +44,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/src/RecursivePublishable.php b/src/RecursivePublishable.php index c25698bc..0407b353 100644 --- a/src/RecursivePublishable.php +++ b/src/RecursivePublishable.php @@ -381,7 +381,9 @@ public function unlinkDisownedRelationship($source, $targetStage, $relationship) } // Find table and field to join on - $joinField = $schema->getRemoteJoinField(get_class($owner), $relationship, 'has_many', $polymorphic); + $hasManyDetails = $schema->getHasManyComponentDetails(get_class($owner), $relationship); + $polymorphic = $hasManyDetails['polymorphic']; + $joinField = $hasManyDetails['joinField']; $joinTable = DataObject::getSchema()->tableForField( $joinClass, $polymorphic ? "{$joinField}ID" : $joinField @@ -391,13 +393,20 @@ public function unlinkDisownedRelationship($source, $targetStage, $relationship) $targetTable = $versioned->stageTable($joinTable, $targetStage); $disowned = new SQLUpdate("\"{$targetTable}\""); if ($polymorphic) { + $where = [ + "\"{$targetTable}\".\"{$joinField}ID\"" => $owner->ID, + "\"{$targetTable}\".\"{$joinField}Class\"" => get_class($owner), + ]; + + if ($hasManyDetails['needsRelation']) { + $disowned->assign("\"{$joinField}Relation\"", null); + $where["\"{$targetTable}\".\"{$joinField}Relation\""] = $relationship; + } + $disowned ->assign("\"{$joinField}ID\"", 0) ->assign("\"{$joinField}Class\"", null) - ->addWhere([ - "\"{$targetTable}\".\"{$joinField}ID\"" => $owner->ID, - "\"{$targetTable}\".\"{$joinField}Class\"" => get_class($owner), - ]); + ->addWhere($where); } else { $disowned ->assign("\"{$joinField}\"", 0)