From f4c739c1793ec07a2b76f820fce0783d8789a9bd Mon Sep 17 00:00:00 2001 From: Albert Siersema Date: Mon, 19 Jun 2023 05:22:41 +0200 Subject: [PATCH] Fixes #14975 (Widget part) (#15076) --- app/Models/DeviceGroup.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/DeviceGroup.php b/app/Models/DeviceGroup.php index b9c64dc7aa..e1a44bb307 100644 --- a/app/Models/DeviceGroup.php +++ b/app/Models/DeviceGroup.php @@ -129,7 +129,9 @@ class DeviceGroup extends BaseModel public function services(): BelongsToMany { - return $this->belongsToMany(\App\Models\Service::class, 'device_group_device', 'device_group_id', 'device_id'); + // $parentKey='id', $relatedKey='device_id' is required to generate the right SQL query. + // Otherwise the primaryKey in Service.php will be used + return $this->belongsToMany(\App\Models\Service::class, 'device_group_device', 'device_group_id', 'device_id', 'id', 'device_id'); } public function users(): BelongsToMany