mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-05-08 04:00:14 -05:00
refactor: split tmdb into movie_id and tv_id
Step 2 in cleaner meta fetching code.
This commit is contained in:
@@ -60,7 +60,7 @@ class Company extends Model
|
||||
*/
|
||||
public function movieTorrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Torrent::class, 'company_movie', 'movie_id', 'company_id', 'id', 'tmdb')->whereRelation('category', 'movie_meta', '=', true);
|
||||
return $this->belongsToMany(Torrent::class, 'company_movie', 'movie_id', 'company_id', 'id', 'movie_id')->whereRelation('category', 'movie_meta', '=', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,6 +68,6 @@ class Company extends Model
|
||||
*/
|
||||
public function tvTorrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Torrent::class, 'company_tv', 'tv_id', 'company_id', 'id', 'tmdb')->whereRelation('category', 'tv_meta', '=', true);
|
||||
return $this->belongsToMany(Torrent::class, 'company_tv', 'tv_id', 'company_id', 'id', 'tv_id')->whereRelation('category', 'tv_meta', '=', true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class Movie extends Model
|
||||
*/
|
||||
public function torrents(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Torrent::class, 'tmdb', 'id')->whereRelation('category', 'movie_meta', '=', true);
|
||||
return $this->hasMany(Torrent::class)->whereRelation('category', 'movie_meta', '=', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ class Movie extends Model
|
||||
*/
|
||||
public function requests(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(TorrentRequest::class, 'tmdb', 'id')->whereRelation('category', 'movie_meta', '=', true);
|
||||
return $this->hasMany(TorrentRequest::class)->whereRelation('category', 'movie_meta', '=', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,6 @@ class Network extends Model
|
||||
*/
|
||||
public function tvTorrents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Torrent::class, 'network_tv', 'tv_id', 'network_id', 'id', 'tmdb')->whereRelation('category', 'tv_meta', '=', true);
|
||||
return $this->belongsToMany(Torrent::class, 'network_tv', 'tv_id', 'network_id', 'id', 'tv_id')->whereRelation('category', 'tv_meta', '=', true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Season extends Model
|
||||
*/
|
||||
public function torrents(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Torrent::class, 'tmdb', 'tv_id')->whereRelation('category', 'tv_meta', '=', true);
|
||||
return $this->hasMany(Torrent::class, 'tv_id', 'tv_id')->whereRelation('category', 'tv_meta', '=', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+23
-17
@@ -50,7 +50,8 @@ use Laravel\Scout\Searchable;
|
||||
* @property int $user_id
|
||||
* @property int $imdb
|
||||
* @property int $tvdb
|
||||
* @property int $tmdb
|
||||
* @property int|null $movie_id
|
||||
* @property int|null $tv_id
|
||||
* @property int $mal
|
||||
* @property int $igdb
|
||||
* @property int|null $season_number
|
||||
@@ -95,7 +96,8 @@ class Torrent extends Model
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array{
|
||||
* tmdb: 'int',
|
||||
* movie_id: 'int',
|
||||
* tv_id: 'int',
|
||||
* igdb: 'int',
|
||||
* status: class-string<ModerationStatus>,
|
||||
* bumped_at: 'datetime',
|
||||
@@ -112,7 +114,8 @@ class Torrent extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'tmdb' => 'int',
|
||||
'movie_id' => 'int',
|
||||
'tv_id' => 'int',
|
||||
'igdb' => 'int',
|
||||
'bumped_at' => 'datetime',
|
||||
'fl_until' => 'datetime',
|
||||
@@ -161,7 +164,8 @@ class Torrent extends Model
|
||||
torrents.user_id,
|
||||
torrents.imdb,
|
||||
torrents.tvdb,
|
||||
torrents.tmdb,
|
||||
torrents.movie_id,
|
||||
torrents.tv_id,
|
||||
torrents.mal,
|
||||
torrents.igdb,
|
||||
torrents.season_number,
|
||||
@@ -285,7 +289,7 @@ class Torrent extends Model
|
||||
SELECT vote_average
|
||||
FROM movies
|
||||
WHERE
|
||||
torrents.tmdb = movies.id
|
||||
torrents.movie_id = movies.id
|
||||
AND torrents.category_id in (
|
||||
SELECT id
|
||||
FROM categories
|
||||
@@ -295,7 +299,7 @@ class Torrent extends Model
|
||||
SELECT vote_average
|
||||
FROM tv
|
||||
WHERE
|
||||
torrents.tmdb = tv.id
|
||||
torrents.tv_id = tv.id
|
||||
AND torrents.category_id in (
|
||||
SELECT id
|
||||
FROM categories
|
||||
@@ -331,7 +335,7 @@ class Torrent extends Model
|
||||
WHERE companies.id IN (
|
||||
SELECT company_id
|
||||
FROM company_movie
|
||||
WHERE company_movie.movie_id = torrents.tmdb
|
||||
WHERE company_movie.movie_id = torrents.movie_id
|
||||
)
|
||||
),
|
||||
'genres', (
|
||||
@@ -343,7 +347,7 @@ class Torrent extends Model
|
||||
WHERE genres.id IN (
|
||||
SELECT genre_id
|
||||
FROM genre_movie
|
||||
WHERE genre_movie.movie_id = torrents.tmdb
|
||||
WHERE genre_movie.movie_id = torrents.movie_id
|
||||
)
|
||||
),
|
||||
'collection', (
|
||||
@@ -363,7 +367,7 @@ class Torrent extends Model
|
||||
)
|
||||
)
|
||||
FROM movies
|
||||
WHERE torrents.tmdb = movies.id
|
||||
WHERE torrents.movie_id = movies.id
|
||||
AND torrents.category_id in (
|
||||
SELECT id
|
||||
FROM categories
|
||||
@@ -388,7 +392,7 @@ class Torrent extends Model
|
||||
WHERE companies.id IN (
|
||||
SELECT company_id
|
||||
FROM company_tv
|
||||
WHERE company_tv.tv_id = torrents.id
|
||||
WHERE company_tv.tv_id = torrents.tv_id
|
||||
)
|
||||
),
|
||||
'genres', (
|
||||
@@ -400,7 +404,7 @@ class Torrent extends Model
|
||||
WHERE genres.id IN (
|
||||
SELECT genre_id
|
||||
FROM genre_tv
|
||||
WHERE genre_tv.tv_id = torrents.tmdb
|
||||
WHERE genre_tv.tv_id = torrents.tv_id
|
||||
)
|
||||
),
|
||||
'networks', (
|
||||
@@ -412,7 +416,7 @@ class Torrent extends Model
|
||||
WHERE networks.id IN (
|
||||
SELECT network_id
|
||||
FROM network_tv
|
||||
WHERE network_tv.tv_id = torrents.id
|
||||
WHERE network_tv.tv_id = torrents.tv_id
|
||||
)
|
||||
),
|
||||
'wishes', (
|
||||
@@ -424,7 +428,7 @@ class Torrent extends Model
|
||||
)
|
||||
)
|
||||
FROM tv
|
||||
WHERE torrents.tmdb = tv.id
|
||||
WHERE torrents.tv_id = tv.id
|
||||
AND torrents.category_id in (
|
||||
SELECT id
|
||||
FROM categories
|
||||
@@ -544,7 +548,7 @@ class Torrent extends Model
|
||||
*/
|
||||
public function movie(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Movie::class, 'tmdb');
|
||||
return $this->belongsTo(Movie::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -554,7 +558,7 @@ class Torrent extends Model
|
||||
*/
|
||||
public function tv(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tv::class, 'tmdb');
|
||||
return $this->belongsTo(Tv::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -837,7 +841,8 @@ class Torrent extends Model
|
||||
'user_id',
|
||||
'imdb',
|
||||
'tvdb',
|
||||
'tmdb',
|
||||
'movie_id',
|
||||
'tv_id',
|
||||
'mal',
|
||||
'igdb',
|
||||
'season_number',
|
||||
@@ -907,7 +912,8 @@ class Torrent extends Model
|
||||
'user_id' => $torrent->user_id,
|
||||
'imdb' => $torrent->imdb,
|
||||
'tvdb' => $torrent->tvdb,
|
||||
'tmdb' => $torrent->tmdb,
|
||||
'movie_id' => $torrent->movie_id,
|
||||
'tv_id' => $torrent->tv_id,
|
||||
'mal' => $torrent->mal,
|
||||
'igdb' => $torrent->igdb,
|
||||
'season_number' => $torrent->season_number,
|
||||
|
||||
@@ -28,7 +28,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property int $category_id
|
||||
* @property int|null $imdb
|
||||
* @property int|null $tvdb
|
||||
* @property int|null $tmdb
|
||||
* @property int|null $movie_id
|
||||
* @property int|null $tv_id
|
||||
* @property int|null $mal
|
||||
* @property int $igdb
|
||||
* @property string $description
|
||||
@@ -72,14 +73,23 @@ class TorrentRequest extends Model
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array{filled_when: 'datetime', approved_when: 'datetime', tmdb: 'int', igdb: 'int', bounty: 'decimal:2', anon: 'bool'}
|
||||
* @return array{
|
||||
* filled_when: 'datetime',
|
||||
* approved_when: 'datetime',
|
||||
* movie_id: 'int',
|
||||
* tv_id: 'int',
|
||||
* igdb: 'int',
|
||||
* bounty: 'decimal:2',
|
||||
* anon: 'bool'
|
||||
* }
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'filled_when' => 'datetime',
|
||||
'approved_when' => 'datetime',
|
||||
'tmdb' => 'int',
|
||||
'movie_id' => 'int',
|
||||
'tv_id' => 'int',
|
||||
'igdb' => 'int',
|
||||
'bounty' => 'decimal:2',
|
||||
'anon' => 'bool',
|
||||
@@ -172,7 +182,7 @@ class TorrentRequest extends Model
|
||||
*/
|
||||
public function movie(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Movie::class, 'tmdb');
|
||||
return $this->belongsTo(Movie::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +192,7 @@ class TorrentRequest extends Model
|
||||
*/
|
||||
public function tv(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Tv::class, 'tmdb');
|
||||
return $this->belongsTo(Tv::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ class Tv extends Model
|
||||
*/
|
||||
public function torrents(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Torrent::class, 'tmdb', 'id')->whereRelation('category', 'tv_meta', '=', true);
|
||||
return $this->hasMany(Torrent::class)->whereRelation('category', 'tv_meta', '=', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -62,7 +62,7 @@ class Wish extends Model
|
||||
*/
|
||||
public function movieTorrents(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Torrent::class, 'tmdb', 'movie_id')
|
||||
return $this->hasMany(Torrent::class, 'movie_id', 'movie_id')
|
||||
->whereRelation('category', 'movie_meta', '=', true);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class Wish extends Model
|
||||
*/
|
||||
public function tvTorrents(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Torrent::class, 'tmdb', 'tv_id')
|
||||
return $this->hasMany(Torrent::class, 'tv_id', 'tv_id')
|
||||
->whereRelation('category', 'tv_meta', '=', true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user