Eager Load Mod Relationships in Scout Model Methods

This commit is contained in:
Refringe 2024-10-01 09:20:17 -04:00
parent 8b71dc2c02
commit 293e52726b
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k

View File

@ -108,6 +108,11 @@ class Mod extends Model
*/ */
public function toSearchableArray(): array public function toSearchableArray(): array
{ {
$this->load([
'latestVersion',
'latestVersion.latestSptVersion',
]);
return [ return [
'id' => $this->id, 'id' => $this->id,
'name' => $this->name, 'name' => $this->name,
@ -138,6 +143,12 @@ class Mod extends Model
return false; return false;
} }
// Eager load the latest mod version, and it's latest SPT version.
$this->load([
'latestVersion',
'latestVersion.latestSptVersion',
]);
// Ensure the mod has a latest version. // Ensure the mod has a latest version.
if ($this->latestVersion()->doesntExist()) { if ($this->latestVersion()->doesntExist()) {
return false; return false;