Skip to content

Avoid duplicate column suggestions in search bar #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ protected function fetchColumnSuggestions($searchTerm)
$model = $this->getModel();
$query = $model::on($this->getDb());

// Ordinary columns first
foreach (self::collectFilterColumns($model, $query->getResolver()) as $columnName => $columnMeta) {
yield $columnName => $columnMeta;
}
Expand Down Expand Up @@ -296,9 +295,9 @@ public static function collectFilterColumns(Model $model, Resolver $resolver): G
self::collectRelations($resolver, $model, $models, []);
}

foreach ($models as $path => $model) {
/** @var Model $model */
foreach ($resolver->getColumnDefinitions($model) as $columnName => $definition) {
foreach ($models as $path => $targetModel) {
/** @var Model $targetModel */
foreach ($resolver->getColumnDefinitions($targetModel) as $columnName => $definition) {
yield $path . '.' . $columnName => $definition->getLabel();
}
}
Expand Down Expand Up @@ -368,8 +367,11 @@ protected static function collectRelations(Resolver $resolver, Model $subject, a
}

$relationPath = array_merge($path, $relationPath);
$models[join('.', $relationPath)] = $relation->getTarget();
self::collectRelations($resolver, $relation->getTarget(), $models, $relationPath);

if (! in_array($relation->getTarget(), $models)) {
$models[join('.', $relationPath)] = $relation->getTarget();
self::collectRelations($resolver, $relation->getTarget(), $models, $relationPath);
}
}
}
}
Expand Down