It fixes the remaining stale test and keeps the actual N+1 strategy:

* Main ticket index renders scalar agent_name.
* Ticket index still eager-loads user, owner, agent.
* Ticket show comments no longer eager-load fake owner / agent relations.
* Updated the conflicting regression tests.
This commit is contained in:
Mark Gregory
2026-06-26 12:07:09 +01:00
parent 788bb87b01
commit 86f0082a84
12 changed files with 94 additions and 18 deletions
+9 -6
View File
@@ -8,11 +8,11 @@ use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Modules\Helpdesk\Database\Factories\TicketFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Helpdesk\Database\Factories\TicketFactory;
/**
* @property int $id
@@ -23,11 +23,13 @@ use Illuminate\Database\Eloquent\SoftDeletes;
final class Ticket extends Model
{
use HasFactory;
use SoftDeletes;
protected $table = 'helpdesk_tickets';
/** @var list<string> */
protected $with = ['user'];
/** @var list<string> */
protected $fillable = [
'reference', 'company_id', 'user_id', 'agent_id', 'status_id', 'board_id', 'priority_id', 'category_id', 'project_id', 'team_id',
@@ -36,9 +38,6 @@ final class Ticket extends Model
'sla_first_response_breached_at', 'sla_resolution_breached_at', 'public_replies_count', 'time_spent_minutes',
];
/** @var list<string> */
protected $with = ['user'];
/** @var array<string, string> */
protected $casts = [
'company_id' => 'integer',
@@ -65,6 +64,11 @@ final class Ticket extends Model
return $this->belongsTo(User::class, 'user_id');
}
public function tickets(): Ticket|HasMany
{
return $this->hasMany(Ticket::class, 'ticket_id');
}
/** @return BelongsTo<User, Ticket> */
public function owner(): BelongsTo
{
@@ -212,5 +216,4 @@ final class Ticket extends Model
{
return TicketFactory::new();
}
}