Merge pull request #9678 from creative-commoners/pulls/4.6/compare-select

FIX Problem with direct compare in SELECT statement causing incompatibility with SQL Server database
This commit is contained in:
Serge Latyntsev 2020-09-10 16:29:21 +12:00 committed by GitHub
commit b13453c88d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

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,