Skip to content

Commit

Permalink
Merge pull request #11127 from lekoala/patch-45
Browse files Browse the repository at this point in the history
FIX Unknown column 'ClassName' in field list
  • Loading branch information
GuySartorelli authored Feb 12, 2024
2 parents e87c724 + e0107e0 commit 9c4266c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ORM/DataQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,19 @@ public function getFinalisedQuery($queriedColumns = null)
$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);
}
}
}

Expand Down

0 comments on commit 9c4266c

Please sign in to comment.