FIX Problem with direct compare in SELECT statement causing incompatibility with SQL Server database

Co-authored-by: Tomas Bilek
This commit is contained in:
Steve Boyd 2020-09-10 14:48:09 +12:00
parent 27c1c72912
commit 02827a6670

View File

@ -96,11 +96,10 @@ class DBForeignKey extends DBInt
// Remove distinct. Applying distinct shouldn't be required provided relations are not applied.
$dataQuery->setDistinct(false);
$dataQuery->setSelect(['over_threshold' => 'count(*) > ' . (int) $threshold]);
$dataQuery->setSelect(['over_threshold' => '(CASE WHEN count(*) > ' . (int)$threshold . ' THEN 1 ELSE 0 END)']);
$result = $dataQuery->execute()->column('over_threshold');
// Checking for 't' supports PostgreSQL before silverstripe/postgresql@2.2
$overThreshold = !empty($result) && ($result[0] === 't' || (int) $result[0] === 1);
$overThreshold = !empty($result) && ((int) $result[0] === 1);
static::$foreignListCache[$hasOneClass] = [
'overThreshold' => $overThreshold,