mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
FIX #108 - Update and simplify getDirtyIDs method
This commit is contained in:
parent
e56a369656
commit
167597db7b
@ -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();
|
||||
// foreignkey identifies a has_one column on the model linked via the has_many relation
|
||||
$ids = DataObject::get($step['otherclass'])
|
||||
->filter('ID', $ids)
|
||||
->column($step['foreignkey']);
|
||||
}
|
||||
|
||||
if (empty($ids)) {
|
||||
|
Loading…
Reference in New Issue
Block a user