Skip to content

Commit

Permalink
[Add] Nova Model Eager Loading
Browse files Browse the repository at this point in the history
- Added eager loading to `Anime`, `Game`, `Manga` and `Season` models
  • Loading branch information
kiritokatklian committed Dec 2, 2024
1 parent 988d0c6 commit 57bfce3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/Nova/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class Anime extends Resource
'id', 'tvdb_id', 'mal_id', 'slug', 'original_title'
];

/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = [
'media',
'media_type',
'tv_rating',
'country_of_origin',
'status',
'source',
'translation'
];

/**
* The logical group associated with the resource.
*
Expand Down
15 changes: 15 additions & 0 deletions app/Nova/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ class Game extends Resource
'id', 'slug', 'original_title'
];

/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = [
'media',
'media_type',
'tv_rating',
'country_of_origin',
'status',
'source',
'translation'
];

/**
* The logical group associated with the resource.
*
Expand Down
15 changes: 15 additions & 0 deletions app/Nova/Manga.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ class Manga extends Resource
'id', 'mal_id', 'slug', 'original_title'
];

/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = [
'media',
'media_type',
'tv_rating',
'country_of_origin',
'status',
'source',
'translation'
];

/**
* The logical group associated with the resource.
*
Expand Down
12 changes: 11 additions & 1 deletion app/Nova/Season.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class Season extends Resource
'id'
];

/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = [
'anime',
'translation'
];

/**
* The logical group associated with the resource.
*
Expand Down Expand Up @@ -161,7 +171,7 @@ public function fields(Request $request): array
public function title(): string
{
$season = $this->resource;
$seasonName = $season->title;
$seasonName = ''; // $season->title;

if (!is_string($seasonName) || !strlen($seasonName)) {
$seasonName = 'No season title';
Expand Down

0 comments on commit 57bfce3

Please sign in to comment.