Merge pull request #280 from chrometoasters/pulls/fix-108-getDirtyIDs-ss3
FIX #108 for SS 3.x - Update and simplify getDirtyIDs method
This commit is contained in:
commit
fa502730d5
|
@ -598,16 +598,14 @@ abstract class SearchIndex extends ViewableData
|
|||
|
||||
foreach ($derivation['chain'] as $step) {
|
||||
if ($step['through'] == 'has_one') {
|
||||
$sql = new SQLQuery('"ID"', '"'.$step['class'].'"', '"'.$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') {
|
||||
$sql = new SQLQuery('"'.$step['class'].'"."ID"', '"'.$step['class'].'"', '"'.$step['otherclass'].'"."ID" IN ('.implode(',', $ids).')');
|
||||
$sql->addInnerJoin($step['otherclass'], '"'.$step['class'].'"."ID" = "'.$step['otherclass'].'"."'.$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