Skip to content

Commit

Permalink
Model: Add left join to relations
Browse files Browse the repository at this point in the history
RedundancyGroup -> DependencyEdge
DependencyEdge -> DependencyNode

The DependecyNodeSummary requires left joins to summarise all available rows,
while the redundancy group joins DependencyEdge and DependencyNode as inner joins, which leads to false positives.
  • Loading branch information
sukhwinder33445 committed Oct 9, 2024
1 parent 9506986 commit 70e3aab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions library/Icingadb/Model/DependencyEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public function createRelations(Relations $relations): void

// "from" and "to" are only necessary for sub-query filters.
$relations->belongsTo('from', DependencyNode::class)
->setCandidateKey('from_node_id');
->setCandidateKey('from_node_id')
->setJoinType('LEFT');

$relations->belongsTo('to', DependencyNode::class)
->setCandidateKey('to_node_id');
->setCandidateKey('to_node_id')
->setJoinType('LEFT');
}
}
11 changes: 7 additions & 4 deletions library/Icingadb/Model/RedundancyGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*
* @property (?RedundancyGroupState)|Query $state
* @property Dependency|Query $dependency
* @property DependencyEdge|Query $from
* @property DependencyEdge|Query $to
* @property (?DependencyEdge)|Query $from
* @property (?DependencyEdge)|Query $to
*/
class RedundancyGroup extends Model
{
Expand Down Expand Up @@ -65,10 +65,13 @@ public function createRelations(Relations $relations): void
$relations->belongsToMany('from', DependencyEdge::class)
->setTargetCandidateKey('from_node_id')
->setTargetForeignKey('id')
->through(DependencyNode::class);
->through(DependencyNode::class)
->setJoinType('LEFT');

$relations->belongsToMany('to', DependencyEdge::class)
->setTargetCandidateKey('to_node_id')
->setTargetForeignKey('id')
->through(DependencyNode::class);
->through(DependencyNode::class)
->setJoinType('LEFT');
}
}

0 comments on commit 70e3aab

Please sign in to comment.