Merge pull request #11127 from lekoala/patch-45

FIX Unknown column 'ClassName' in field list
This commit is contained in:
Guy Sartorelli 2024-02-13 09:51:52 +13:00 committed by GitHub
commit 9c4266c8f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -298,13 +298,19 @@ class DataQuery
$collisionClassColumn = $schema->sqlColumnForField($collisionClass, 'ClassName'); $collisionClassColumn = $schema->sqlColumnForField($collisionClass, 'ClassName');
$collisionClasses = ClassInfo::subclassesFor($collisionClass); $collisionClasses = ClassInfo::subclassesFor($collisionClass);
$collisionClassesSQL = implode(', ', Convert::raw2sql($collisionClasses, true)); $collisionClassesSQL = implode(', ', Convert::raw2sql($collisionClasses, true));
$caseClauses[] = "WHEN {$collisionClassColumn} IN ({$collisionClassesSQL}) THEN $collision"; // Only add clause if this is already joined to avoid "Unknown column 'ClassName'" error
$collisionTableForClassName = $schema->tableForField($collisionClass, 'ClassName');
if (array_key_exists($collisionTableForClassName, $query->getFrom())) {
$caseClauses[] = "WHEN {$collisionClassColumn} IN ({$collisionClassesSQL}) THEN $collision";
}
} }
} else { } else {
user_error("Bad collision item '$collision'", E_USER_WARNING); user_error("Bad collision item '$collision'", E_USER_WARNING);
} }
} }
$query->selectField("CASE " . implode(" ", $caseClauses) . " ELSE NULL END", $collisionField); if (!empty($caseClauses)) {
$query->selectField("CASE " . implode(" ", $caseClauses) . " ELSE NULL END", $collisionField);
}
} }
} }