mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #11127 from lekoala/patch-45
FIX Unknown column 'ClassName' in field list
This commit is contained in:
commit
9c4266c8f3
@ -298,13 +298,19 @@ class DataQuery
|
||||
$collisionClassColumn = $schema->sqlColumnForField($collisionClass, 'ClassName');
|
||||
$collisionClasses = ClassInfo::subclassesFor($collisionClass);
|
||||
$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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user