From feb2dad15fa2385386e6bbb1fb11bd11d802bc85 Mon Sep 17 00:00:00 2001 From: Michal Kleiner Date: Fri, 30 Nov 2018 13:21:21 +1300 Subject: [PATCH] FIX #108 - Update and simplify getDirtyIDs method --- src/Search/Indexes/SearchIndex.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Search/Indexes/SearchIndex.php b/src/Search/Indexes/SearchIndex.php index ea8facd..5d144cd 100644 --- a/src/Search/Indexes/SearchIndex.php +++ b/src/Search/Indexes/SearchIndex.php @@ -615,23 +615,15 @@ abstract class SearchIndex extends ViewableData $ids = array($id); foreach ($derivation['chain'] as $step) { - // Use TableName for queries - $tableName = DataObject::getSchema()->tableName($step['class']); - if ($step['through'] == 'has_one') { - $sql = new SQLSelect('"ID"', '"' . $tableName . '"', '"' . $step['foreignkey'] . '" IN (' . implode(',', $ids) . ')'); - singleton($step['class'])->extend('augmentSQL', $sql); - - $ids = $sql->execute()->column(); + $ids = DataObject::get($step['class']) + ->filter($step['foreignkey'], $ids) + ->column('ID'); } elseif ($step['through'] == 'has_many') { - // Use TableName for queries - $otherTableName = DataObject::getSchema()->tableName($step['otherclass']); - - $sql = new SQLSelect('"' . $tableName . '"."ID"', '"' . $tableName . '"', '"' . $otherTableName . '"."ID" IN (' . implode(',', $ids) . ')'); - $sql->addInnerJoin($otherTableName, '"' . $tableName . '"."ID" = "' . $otherTableName . '"."' . $step['foreignkey'] . '"'); - singleton($step['class'])->extend('augmentSQL', $sql); - - $ids = $sql->execute()->column(); + // Get many ids by querying component with alternate set of foreign ids + $ids = DataObject::singleton($step['otherclass']) + ->getComponents($step['method'], $ids) + ->column('ID'); } if (empty($ids)) {