From 92929c45d542b100993da28054ff1086a1082458 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 23 Aug 2020 08:45:39 -0700 Subject: [PATCH] Fix query bug returning _all_ variables; closes #2250 --- app/Models/Server.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Models/Server.php b/app/Models/Server.php index e6e9bca72..91ba9621a 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -4,6 +4,7 @@ namespace Pterodactyl\Models; use Illuminate\Notifications\Notifiable; use Pterodactyl\Models\Traits\Searchable; +use Illuminate\Database\Query\JoinClause; use Znck\Eloquent\Traits\BelongsToThrough; /** @@ -272,7 +273,15 @@ class Server extends Model { return $this->hasMany(EggVariable::class, 'egg_id', 'egg_id') ->select(['egg_variables.*', 'server_variables.variable_value as server_value']) - ->leftJoin('server_variables', 'server_variables.variable_id', '=', 'egg_variables.id'); + ->leftJoin('server_variables', function (JoinClause $join) { + // Don't forget to join against the server ID as well since the way we're using this relationship + // would actually return all of the variables and their values for _all_ servers using that egg,\ + // rather than only the server for this model. + // + // @see https://github.com/pterodactyl/panel/issues/2250 + $join->on('server_variables.variable_id', 'egg_variables.id') + ->where('server_variables.server_id', $this->id); + }); } /**