FIX Handle polymorphic relationships that use Owner instead of Parent

This commit is contained in:
Steve Boyd 2024-01-10 11:43:26 +13:00
parent b1a1d4b951
commit 9bfb731bc3

View File

@ -313,9 +313,10 @@ class StandardRelatedDataService implements RelatedDataService
$tableName = $this->dataObjectSchema->tableName($class); $tableName = $this->dataObjectSchema->tableName($class);
$where = sprintf('"%s" = %u', $componentIDField, $record->ID); $where = sprintf('"%s" = %u', $componentIDField, $record->ID);
// Polymorphic // Polymorphic - if $component is "Parent" or "Owner" then usually it will be polymorphic
if ($componentIDField === 'ParentID' && isset($dbFields['ParentClass'])) { $isPolymorphic = DataObject::getSchema()->hasOneComponent($class, $component) === DataObject::class;
$where .= sprintf(' AND "ParentClass" = %s', $this->prepareClassNameLiteral(get_class($record))); if ($isPolymorphic) {
$where .= sprintf(' AND "' . $component . 'Class" = %s', $this->prepareClassNameLiteral(get_class($record)));
} }
// Example SQL: // Example SQL: