Skip to content

Commit 92929c4

Browse files
committed
Fix query bug returning _all_ variables; closes pterodactyl#2250
1 parent f21aca2 commit 92929c4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/Models/Server.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Notifications\Notifiable;
66
use Pterodactyl\Models\Traits\Searchable;
7+
use Illuminate\Database\Query\JoinClause;
78
use Znck\Eloquent\Traits\BelongsToThrough;
89

910
/**
@@ -272,7 +273,15 @@ public function variables()
272273
{
273274
return $this->hasMany(EggVariable::class, 'egg_id', 'egg_id')
274275
->select(['egg_variables.*', 'server_variables.variable_value as server_value'])
275-
->leftJoin('server_variables', 'server_variables.variable_id', '=', 'egg_variables.id');
276+
->leftJoin('server_variables', function (JoinClause $join) {
277+
// Don't forget to join against the server ID as well since the way we're using this relationship
278+
// would actually return all of the variables and their values for _all_ servers using that egg,\
279+
// rather than only the server for this model.
280+
//
281+
// @see https://github.com/pterodactyl/panel/issues/2250
282+
$join->on('server_variables.variable_id', 'egg_variables.id')
283+
->where('server_variables.server_id', $this->id);
284+
});
276285
}
277286

278287
/**

0 commit comments

Comments
 (0)