Fix failed to resolve reversed host/service -> comment relations (#858)

fixes #827
This commit is contained in:
Yonas Habteab 2023-09-06 13:50:44 +02:00 committed by GitHub
commit cacc770ce5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 9 deletions

View file

@ -108,13 +108,7 @@ class Comment extends Model
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class)->setJoinType('LEFT');
$relations->belongsTo('host_state', HostState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
$relations->belongsTo('service', Service::class)->setJoinType('LEFT');
$relations->belongsTo('service_state', ServiceState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
$relations->belongsTo('zone', Zone::class);
}
}

View file

@ -61,7 +61,7 @@ class HostState extends State
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('host', Host::class);
$relations->hasOne('last_comment', Comment::class)
$relations->hasOne('last_comment', LastHostComment::class)
->setCandidateKey('last_comment_id')
->setForeignKey('id')
->setJoinType('LEFT');

View file

@ -0,0 +1,19 @@
<?php
/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Model;
use ipl\Orm\Relations;
class LastHostComment extends Comment
{
public function createRelations(Relations $relations): void
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('zone', Zone::class);
$relations->belongsTo('state', HostState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
}
}

View file

@ -0,0 +1,19 @@
<?php
/* Icinga DB Web | (c) 2023 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Model;
use ipl\Orm\Relations;
class LastServiceComment extends Comment
{
public function createRelations(Relations $relations): void
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('zone', Zone::class);
$relations->belongsTo('state', ServiceState::class)
->setForeignKey('last_comment_id')
->setCandidateKey('id');
}
}

View file

@ -58,7 +58,7 @@ class ServiceState extends State
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('service', Service::class);
$relations->hasOne('last_comment', Comment::class)
$relations->hasOne('last_comment', LastServiceComment::class)
->setCandidateKey('last_comment_id')
->setForeignKey('id')
->setJoinType('LEFT');

View file

@ -387,7 +387,7 @@ class ObjectSuggestions extends Suggestions
/** @var Relation $relation */
if (
empty($path) || (
$name === 'state'
($name === 'state' && $path[count($path) - 1] !== 'last_comment')
|| $name === 'last_comment'
|| $name === 'notificationcommand' && $path[0] === 'notification'
)