feat: add IDs for pivots (#1149)

This commit is contained in:
Kyrch
2026-04-02 12:39:11 -03:00
committed by GitHub
parent 3ec851fc23
commit 8d350a89f4
28 changed files with 75 additions and 178 deletions
+1
View File
@@ -24,6 +24,7 @@ yarn-error.log
auth.json auth.json
*.sqlite *.sqlite
*.sqlite3 *.sqlite3
*.sql
public/css/app.css public/css/app.css
public/js/app.js public/js/app.js
test.php test.php
+1 -1
View File
@@ -199,7 +199,7 @@ class Playlist extends BaseModel implements HasAggregateLikes, HasHashids, HasIm
return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE)
->using(Imageable::class) ->using(Imageable::class)
->as('playlistimage') ->as('playlistimage')
->withPivot(Imageable::ATTRIBUTE_DEPTH) ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
+4 -2
View File
@@ -224,6 +224,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has
return $this->belongsToMany(Series::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_ANIME, AnimeSeries::ATTRIBUTE_SERIES) return $this->belongsToMany(Series::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_ANIME, AnimeSeries::ATTRIBUTE_SERIES)
->using(AnimeSeries::class) ->using(AnimeSeries::class)
->as(AnimeSeriesJsonResource::$wrap) ->as(AnimeSeriesJsonResource::$wrap)
->withPivot(AnimeSeries::ATTRIBUTE_ID)
->withTimestamps(); ->withTimestamps();
} }
@@ -242,8 +243,8 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has
{ {
return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('animeresource') ->as('animeresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -255,7 +256,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has
return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE)
->using(Imageable::class) ->using(Imageable::class)
->as('animeimage') ->as('animeimage')
->withPivot(Imageable::ATTRIBUTE_DEPTH) ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
@@ -267,6 +268,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has
return $this->belongsToMany(Studio::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_ANIME, AnimeStudio::ATTRIBUTE_STUDIO) return $this->belongsToMany(Studio::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_ANIME, AnimeStudio::ATTRIBUTE_STUDIO)
->using(AnimeStudio::class) ->using(AnimeStudio::class)
->as(AnimeStudioJsonResource::$wrap) ->as(AnimeStudioJsonResource::$wrap)
->withPivot(AnimeStudio::ATTRIBUTE_ID)
->withTimestamps(); ->withTimestamps();
} }
@@ -208,6 +208,7 @@ class AnimeThemeEntry extends BaseModel implements Auditable, HasAggregateLikes,
) )
->using(AnimeThemeEntryVideo::class) ->using(AnimeThemeEntryVideo::class)
->as(AnimeThemeEntryVideoJsonResource::$wrap) ->as(AnimeThemeEntryVideoJsonResource::$wrap)
->withPivot([AnimeThemeEntryVideo::ATTRIBUTE_ID])
->withTimestamps(); ->withTimestamps();
} }
@@ -218,8 +219,8 @@ class AnimeThemeEntry extends BaseModel implements Auditable, HasAggregateLikes,
{ {
return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('entryresource') ->as('entryresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
+17 -4
View File
@@ -191,6 +191,7 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha
->using(ArtistSong::class) ->using(ArtistSong::class)
->withPivot([ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS]) ->withPivot([ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS])
->as(ArtistSongJsonResource::$wrap) ->as(ArtistSongJsonResource::$wrap)
->withPivot(ArtistSong::ATTRIBUTE_ID)
->withTimestamps(); ->withTimestamps();
} }
@@ -254,8 +255,14 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha
{ {
return $this->belongsToMany(Artist::class, ArtistMember::TABLE, ArtistMember::ATTRIBUTE_ARTIST, ArtistMember::ATTRIBUTE_MEMBER) return $this->belongsToMany(Artist::class, ArtistMember::TABLE, ArtistMember::ATTRIBUTE_ARTIST, ArtistMember::ATTRIBUTE_MEMBER)
->using(ArtistMember::class) ->using(ArtistMember::class)
->withPivot([ArtistMember::ATTRIBUTE_ALIAS, ArtistMember::ATTRIBUTE_AS, ArtistMember::ATTRIBUTE_NOTES, ArtistMember::ATTRIBUTE_RELEVANCE])
->as(ArtistMemberJsonResource::$wrap) ->as(ArtistMemberJsonResource::$wrap)
->withPivot([
ArtistMember::ATTRIBUTE_ID,
ArtistMember::ATTRIBUTE_ALIAS,
ArtistMember::ATTRIBUTE_AS,
ArtistMember::ATTRIBUTE_NOTES,
ArtistMember::ATTRIBUTE_RELEVANCE,
])
->withTimestamps(); ->withTimestamps();
} }
@@ -266,8 +273,14 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha
{ {
return $this->belongsToMany(Artist::class, ArtistMember::TABLE, ArtistMember::ATTRIBUTE_MEMBER, ArtistMember::ATTRIBUTE_ARTIST) return $this->belongsToMany(Artist::class, ArtistMember::TABLE, ArtistMember::ATTRIBUTE_MEMBER, ArtistMember::ATTRIBUTE_ARTIST)
->using(ArtistMember::class) ->using(ArtistMember::class)
->withPivot([ArtistMember::ATTRIBUTE_ALIAS, ArtistMember::ATTRIBUTE_AS, ArtistMember::ATTRIBUTE_NOTES])
->as(ArtistMemberJsonResource::$wrap) ->as(ArtistMemberJsonResource::$wrap)
->withPivot([
ArtistMember::ATTRIBUTE_ID,
ArtistMember::ATTRIBUTE_ALIAS,
ArtistMember::ATTRIBUTE_AS,
ArtistMember::ATTRIBUTE_NOTES,
ArtistMember::ATTRIBUTE_RELEVANCE,
])
->withTimestamps(); ->withTimestamps();
} }
@@ -278,8 +291,8 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha
{ {
return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('artistresource') ->as('artistresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -290,8 +303,8 @@ class Artist extends BaseModel implements Auditable, HasImages, HasResources, Ha
{ {
return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE)
->using(Imageable::class) ->using(Imageable::class)
->withPivot(Imageable::ATTRIBUTE_DEPTH)
->as('artistimage') ->as('artistimage')
->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
} }
+5 -5
View File
@@ -114,8 +114,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable
{ {
return $this->morphedByMany(Anime::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) return $this->morphedByMany(Anime::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('animeresource') ->as('animeresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -126,8 +126,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable
{ {
return $this->morphedByMany(AnimeThemeEntry::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) return $this->morphedByMany(AnimeThemeEntry::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('entryresource') ->as('entryresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -138,8 +138,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable
{ {
return $this->morphedByMany(Artist::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) return $this->morphedByMany(Artist::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('artistresource') ->as('artistresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -150,8 +150,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable
{ {
return $this->morphedByMany(Song::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) return $this->morphedByMany(Song::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('songresource') ->as('songresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -162,8 +162,8 @@ class ExternalResource extends BaseModel implements Auditable, SoftDeletable
{ {
return $this->morphedByMany(Studio::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID) return $this->morphedByMany(Studio::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('studioresource') ->as('studioresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
} }
+4 -1
View File
@@ -133,6 +133,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable
return $this->morphedByMany(Anime::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) return $this->morphedByMany(Anime::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID)
->using(Imageable::class) ->using(Imageable::class)
->as('animeimage') ->as('animeimage')
->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
@@ -144,7 +145,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable
return $this->morphedByMany(Artist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) return $this->morphedByMany(Artist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID)
->using(Imageable::class) ->using(Imageable::class)
->as('artistimage') ->as('artistimage')
->withPivot(Imageable::ATTRIBUTE_DEPTH) ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
@@ -156,6 +157,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable
return $this->morphedByMany(Studio::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) return $this->morphedByMany(Studio::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID)
->using(Imageable::class) ->using(Imageable::class)
->as('studioimage') ->as('studioimage')
->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
@@ -167,6 +169,7 @@ class Image extends BaseModel implements Auditable, SoftDeletable
return $this->morphedByMany(Playlist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID) return $this->morphedByMany(Playlist::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGE, Imageable::ATTRIBUTE_IMAGEABLE_ID)
->using(Imageable::class) ->using(Imageable::class)
->as('playlistimage') ->as('playlistimage')
->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
} }
+1
View File
@@ -140,6 +140,7 @@ class Series extends BaseModel implements Auditable, SoftDeletable
return $this->belongsToMany(Anime::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_SERIES, AnimeSeries::ATTRIBUTE_ANIME) return $this->belongsToMany(Anime::class, AnimeSeries::TABLE, AnimeSeries::ATTRIBUTE_SERIES, AnimeSeries::ATTRIBUTE_ANIME)
->using(AnimeSeries::class) ->using(AnimeSeries::class)
->as(AnimeSeriesJsonResource::$wrap) ->as(AnimeSeriesJsonResource::$wrap)
->withPivot([AnimeSeries::ATTRIBUTE_ID])
->withTimestamps(); ->withTimestamps();
} }
} }
+2 -2
View File
@@ -155,8 +155,8 @@ class Song extends BaseModel implements Auditable, HasResources, SoftDeletable
{ {
return $this->belongsToMany(Artist::class, ArtistSong::TABLE, ArtistSong::ATTRIBUTE_SONG, ArtistSong::ATTRIBUTE_ARTIST) return $this->belongsToMany(Artist::class, ArtistSong::TABLE, ArtistSong::ATTRIBUTE_SONG, ArtistSong::ATTRIBUTE_ARTIST)
->using(ArtistSong::class) ->using(ArtistSong::class)
->withPivot([ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS])
->as(ArtistSongJsonResource::$wrap) ->as(ArtistSongJsonResource::$wrap)
->withPivot([ArtistSong::ATTRIBUTE_ID, ArtistSong::ATTRIBUTE_ALIAS, ArtistSong::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -175,8 +175,8 @@ class Song extends BaseModel implements Auditable, HasResources, SoftDeletable
{ {
return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('songresource') ->as('songresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
} }
+3 -2
View File
@@ -138,6 +138,7 @@ class Studio extends BaseModel implements Auditable, HasImages, HasResources, So
return $this->belongsToMany(Anime::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_STUDIO, AnimeStudio::ATTRIBUTE_ANIME) return $this->belongsToMany(Anime::class, AnimeStudio::TABLE, AnimeStudio::ATTRIBUTE_STUDIO, AnimeStudio::ATTRIBUTE_ANIME)
->using(AnimeStudio::class) ->using(AnimeStudio::class)
->as(AnimeStudioJsonResource::$wrap) ->as(AnimeStudioJsonResource::$wrap)
->withPivot([AnimeStudio::ATTRIBUTE_ID])
->withTimestamps(); ->withTimestamps();
} }
@@ -148,8 +149,8 @@ class Studio extends BaseModel implements Auditable, HasImages, HasResources, So
{ {
return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE) return $this->morphToMany(ExternalResource::class, Resourceable::RELATION_RESOURCEABLE, Resourceable::TABLE, Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCE)
->using(Resourceable::class) ->using(Resourceable::class)
->withPivot(Resourceable::ATTRIBUTE_AS)
->as('studioresource') ->as('studioresource')
->withPivot([Resourceable::ATTRIBUTE_ID, Resourceable::ATTRIBUTE_AS])
->withTimestamps(); ->withTimestamps();
} }
@@ -161,7 +162,7 @@ class Studio extends BaseModel implements Auditable, HasImages, HasResources, So
return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE) return $this->morphToMany(Image::class, Imageable::RELATION_IMAGEABLE, Imageable::TABLE, Imageable::ATTRIBUTE_IMAGEABLE_ID, Imageable::ATTRIBUTE_IMAGE)
->using(Imageable::class) ->using(Imageable::class)
->as('studioimage') ->as('studioimage')
->withPivot(Imageable::ATTRIBUTE_DEPTH) ->withPivot([Imageable::ATTRIBUTE_ID, Imageable::ATTRIBUTE_DEPTH])
->withTimestamps(); ->withTimestamps();
} }
} }
+1
View File
@@ -310,6 +310,7 @@ class Video extends BaseModel implements Auditable, SoftDeletable, Streamable
return $this->belongsToMany(AnimeThemeEntry::class, AnimeThemeEntryVideo::TABLE, AnimeThemeEntryVideo::ATTRIBUTE_VIDEO, AnimeThemeEntryVideo::ATTRIBUTE_ENTRY) return $this->belongsToMany(AnimeThemeEntry::class, AnimeThemeEntryVideo::TABLE, AnimeThemeEntryVideo::ATTRIBUTE_VIDEO, AnimeThemeEntryVideo::ATTRIBUTE_ENTRY)
->using(AnimeThemeEntryVideo::class) ->using(AnimeThemeEntryVideo::class)
->as(AnimeThemeEntryVideoJsonResource::$wrap) ->as(AnimeThemeEntryVideoJsonResource::$wrap)
->withPivot([AnimeThemeEntryVideo::ATTRIBUTE_ID])
->withTimestamps(); ->withTimestamps();
} }
+9 -22
View File
@@ -4,13 +4,13 @@ declare(strict_types=1);
namespace App\Pivots; namespace App\Pivots;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphPivot; use Illuminate\Database\Eloquent\Relations\MorphPivot;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/** /**
* @property int $id
* @property Carbon $created_at * @property Carbon $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
*/ */
@@ -18,32 +18,19 @@ abstract class BaseMorphPivot extends MorphPivot
{ {
use HasFactory; use HasFactory;
final public const ATTRIBUTE_ID = 'id';
final public const ATTRIBUTE_CREATED_AT = Model::CREATED_AT; final public const ATTRIBUTE_CREATED_AT = Model::CREATED_AT;
final public const ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT; final public const ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = true;
/** /**
* The storage format of the model's date columns. * The storage format of the model's date columns.
*/ */
protected $dateFormat = 'Y-m-d\TH:i:s.u'; protected $dateFormat = 'Y-m-d\TH:i:s.u';
/**
* Set the keys for a select query.
*
* @noinspection PhpMissingParentCallCommonInspection
*/
protected function setKeysForSelectQuery($query): Builder
{
foreach ($this->getPrimaryKeys() as $primaryKey) {
$query->where($primaryKey, $this->getAttribute($primaryKey));
}
return $query;
}
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
abstract protected function getPrimaryKeys(): array;
} }
+9 -22
View File
@@ -4,13 +4,13 @@ declare(strict_types=1);
namespace App\Pivots; namespace App\Pivots;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/** /**
* @property int $id
* @property Carbon $created_at * @property Carbon $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
*/ */
@@ -18,32 +18,19 @@ abstract class BasePivot extends Pivot
{ {
use HasFactory; use HasFactory;
final public const ATTRIBUTE_ID = 'id';
final public const ATTRIBUTE_CREATED_AT = Model::CREATED_AT; final public const ATTRIBUTE_CREATED_AT = Model::CREATED_AT;
final public const ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT; final public const ATTRIBUTE_UPDATED_AT = Model::UPDATED_AT;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = true;
/** /**
* The storage format of the model's date columns. * The storage format of the model's date columns.
*/ */
protected $dateFormat = 'Y-m-d\TH:i:s.u'; protected $dateFormat = 'Y-m-d\TH:i:s.u';
/**
* Set the keys for a select query.
*
* @noinspection PhpMissingParentCallCommonInspection
*/
protected function setKeysForSelectQuery($query): Builder
{
foreach ($this->getPrimaryKeys() as $primaryKey) {
$query->where($primaryKey, $this->getAttribute($primaryKey));
}
return $query;
}
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
abstract protected function getPrimaryKeys(): array;
} }
-14
View File
@@ -13,7 +13,6 @@ use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
/** /**
* @property int $id
* @property Page $page * @property Page $page
* @property int $page_id * @property int $page_id
* @property Role $role * @property Role $role
@@ -27,7 +26,6 @@ class PageRole extends BasePivot
{ {
final public const string TABLE = 'page_roles'; final public const string TABLE = 'page_roles';
final public const string ATTRIBUTE_ID = 'id';
final public const string ATTRIBUTE_PAGE = 'page_id'; final public const string ATTRIBUTE_PAGE = 'page_id';
final public const string ATTRIBUTE_ROLE = 'role_id'; final public const string ATTRIBUTE_ROLE = 'role_id';
final public const string ATTRIBUTE_TYPE = 'type'; final public const string ATTRIBUTE_TYPE = 'type';
@@ -46,18 +44,6 @@ class PageRole extends BasePivot
PageRole::ATTRIBUTE_TYPE, PageRole::ATTRIBUTE_TYPE,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
PageRole::ATTRIBUTE_ID,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
-14
View File
@@ -96,20 +96,6 @@ class Imageable extends BaseMorphPivot
]; ];
} }
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
Imageable::ATTRIBUTE_IMAGE,
Imageable::ATTRIBUTE_IMAGEABLE_TYPE,
Imageable::ATTRIBUTE_IMAGEABLE_ID,
];
}
/** /**
* Gets the image that owns the imageable. * Gets the image that owns the imageable.
* *
-14
View File
@@ -83,20 +83,6 @@ class Resourceable extends BaseMorphPivot
Resourceable::ATTRIBUTE_RESOURCEABLE_ID, Resourceable::ATTRIBUTE_RESOURCEABLE_ID,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
Resourceable::ATTRIBUTE_RESOURCE,
Resourceable::ATTRIBUTE_RESOURCEABLE_TYPE,
Resourceable::ATTRIBUTE_RESOURCEABLE_ID,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
-13
View File
@@ -54,19 +54,6 @@ class AnimeSeries extends BasePivot
AnimeSeries::ATTRIBUTE_SERIES, AnimeSeries::ATTRIBUTE_SERIES,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
AnimeSeries::ATTRIBUTE_ANIME,
AnimeSeries::ATTRIBUTE_SERIES,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
-13
View File
@@ -54,19 +54,6 @@ class AnimeStudio extends BasePivot
AnimeStudio::ATTRIBUTE_STUDIO, AnimeStudio::ATTRIBUTE_STUDIO,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
AnimeStudio::ATTRIBUTE_ANIME,
AnimeStudio::ATTRIBUTE_STUDIO,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
-13
View File
@@ -58,19 +58,6 @@ class AnimeThemeEntryVideo extends BasePivot
AnimeThemeEntryVideo::ATTRIBUTE_VIDEO, AnimeThemeEntryVideo::ATTRIBUTE_VIDEO,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
AnimeThemeEntryVideo::ATTRIBUTE_ENTRY,
AnimeThemeEntryVideo::ATTRIBUTE_VIDEO,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
-13
View File
@@ -67,19 +67,6 @@ class ArtistMember extends BasePivot
ArtistMember::ATTRIBUTE_RELEVANCE, ArtistMember::ATTRIBUTE_RELEVANCE,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
ArtistMember::ATTRIBUTE_ARTIST,
ArtistMember::ATTRIBUTE_MEMBER,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
-13
View File
@@ -46,19 +46,6 @@ class ArtistSong extends BasePivot
ArtistSong::ATTRIBUTE_SONG, ArtistSong::ATTRIBUTE_SONG,
]; ];
/**
* Get the composite primary key for the pivot.
*
* @return string[]
*/
protected function getPrimaryKeys(): array
{
return [
ArtistSong::ATTRIBUTE_ARTIST,
ArtistSong::ATTRIBUTE_SONG,
];
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *
@@ -15,12 +15,13 @@ return new class extends Migration
{ {
if (! Schema::hasTable('anime_series')) { if (! Schema::hasTable('anime_series')) {
Schema::create('anime_series', function (Blueprint $table) { Schema::create('anime_series', function (Blueprint $table) {
$table->id();
$table->timestamps(6); $table->timestamps(6);
$table->unsignedBigInteger('anime_id'); $table->unsignedBigInteger('anime_id');
$table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete(); $table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete();
$table->unsignedBigInteger('series_id'); $table->unsignedBigInteger('series_id');
$table->foreign('series_id')->references('series_id')->on('series')->cascadeOnDelete(); $table->foreign('series_id')->references('series_id')->on('series')->cascadeOnDelete();
$table->primary(['anime_id', 'series_id']); $table->unique(['anime_id', 'series_id'], 'anime_series_unique');
}); });
} }
} }
@@ -15,12 +15,13 @@ return new class extends Migration
{ {
if (! Schema::hasTable('anime_theme_entry_video')) { if (! Schema::hasTable('anime_theme_entry_video')) {
Schema::create('anime_theme_entry_video', function (Blueprint $table) { Schema::create('anime_theme_entry_video', function (Blueprint $table) {
$table->id();
$table->timestamps(6); $table->timestamps(6);
$table->unsignedBigInteger('entry_id'); $table->unsignedBigInteger('entry_id');
$table->foreign('entry_id')->references('entry_id')->on('anime_theme_entries')->cascadeOnDelete(); $table->foreign('entry_id')->references('entry_id')->on('anime_theme_entries')->cascadeOnDelete();
$table->unsignedBigInteger('video_id'); $table->unsignedBigInteger('video_id');
$table->foreign('video_id')->references('video_id')->on('videos')->cascadeOnDelete(); $table->foreign('video_id')->references('video_id')->on('videos')->cascadeOnDelete();
$table->primary(['entry_id', 'video_id']); $table->unique(['entry_id', 'video_id'], 'entry_video_unique');
}); });
} }
} }
@@ -15,14 +15,15 @@ return new class extends Migration
{ {
if (! Schema::hasTable('artist_song')) { if (! Schema::hasTable('artist_song')) {
Schema::create('artist_song', function (Blueprint $table) { Schema::create('artist_song', function (Blueprint $table) {
$table->id();
$table->timestamps(6); $table->timestamps(6);
$table->unsignedBigInteger('artist_id'); $table->unsignedBigInteger('artist_id');
$table->foreign('artist_id')->references('artist_id')->on('artists')->cascadeOnDelete(); $table->foreign('artist_id')->references('artist_id')->on('artists')->cascadeOnDelete();
$table->unsignedBigInteger('song_id'); $table->unsignedBigInteger('song_id');
$table->foreign('song_id')->references('song_id')->on('songs')->cascadeOnDelete(); $table->foreign('song_id')->references('song_id')->on('songs')->cascadeOnDelete();
$table->primary(['artist_id', 'song_id']);
$table->string('as')->nullable(); $table->string('as')->nullable();
$table->string('alias')->nullable(); $table->string('alias')->nullable();
$table->unique(['artist_id', 'song_id'], 'artist_song_unique');
}); });
} }
} }
@@ -15,15 +15,16 @@ return new class extends Migration
{ {
if (! Schema::hasTable('artist_member')) { if (! Schema::hasTable('artist_member')) {
Schema::create('artist_member', function (Blueprint $table) { Schema::create('artist_member', function (Blueprint $table) {
$table->id();
$table->timestamps(6); $table->timestamps(6);
$table->unsignedBigInteger('artist_id'); $table->unsignedBigInteger('artist_id');
$table->foreign('artist_id')->references('artist_id')->on('artists')->cascadeOnDelete(); $table->foreign('artist_id')->references('artist_id')->on('artists')->cascadeOnDelete();
$table->unsignedBigInteger('member_id'); $table->unsignedBigInteger('member_id');
$table->foreign('member_id')->references('artist_id')->on('artists')->cascadeOnDelete(); $table->foreign('member_id')->references('artist_id')->on('artists')->cascadeOnDelete();
$table->primary(['artist_id', 'member_id']);
$table->string('as')->nullable(); $table->string('as')->nullable();
$table->string('alias')->nullable(); $table->string('alias')->nullable();
$table->string('notes')->nullable(); $table->string('notes')->nullable();
$table->unique(['artist_id', 'member_id'], 'artist_member_unique');
}); });
} }
} }
@@ -15,12 +15,13 @@ return new class extends Migration
{ {
if (! Schema::hasTable('anime_studio')) { if (! Schema::hasTable('anime_studio')) {
Schema::create('anime_studio', function (Blueprint $table) { Schema::create('anime_studio', function (Blueprint $table) {
$table->id();
$table->timestamps(6); $table->timestamps(6);
$table->unsignedBigInteger('anime_id'); $table->unsignedBigInteger('anime_id');
$table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete(); $table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete();
$table->unsignedBigInteger('studio_id'); $table->unsignedBigInteger('studio_id');
$table->foreign('studio_id')->references('studio_id')->on('studios')->cascadeOnDelete(); $table->foreign('studio_id')->references('studio_id')->on('studios')->cascadeOnDelete();
$table->primary(['anime_id', 'studio_id']); $table->unique(['anime_id', 'studio_id'], 'anime_studio_unique');
}); });
} }
} }
@@ -15,6 +15,7 @@ return new class extends Migration
{ {
if (! Schema::hasTable('resourceables')) { if (! Schema::hasTable('resourceables')) {
Schema::create('resourceables', function (Blueprint $table) { Schema::create('resourceables', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('resource_id'); $table->unsignedBigInteger('resource_id');
$table->foreign('resource_id')->references('resource_id')->on('resources')->cascadeOnDelete(); $table->foreign('resource_id')->references('resource_id')->on('resources')->cascadeOnDelete();
@@ -23,11 +24,11 @@ return new class extends Migration
$table->timestamps(6); $table->timestamps(6);
$table->primary([ $table->unique([
'resource_id', 'resource_id',
'resourceable_type', 'resourceable_type',
'resourceable_id', 'resourceable_id',
]); ], 'resourceable_unique');
}); });
} }
} }
@@ -15,6 +15,7 @@ return new class extends Migration
{ {
if (! Schema::hasTable('imageables')) { if (! Schema::hasTable('imageables')) {
Schema::create('imageables', function (Blueprint $table) { Schema::create('imageables', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('image_id'); $table->unsignedBigInteger('image_id');
$table->foreign('image_id')->references('image_id')->on('images')->cascadeOnDelete(); $table->foreign('image_id')->references('image_id')->on('images')->cascadeOnDelete();
@@ -23,11 +24,11 @@ return new class extends Migration
$table->timestamps(6); $table->timestamps(6);
$table->primary([ $table->unique([
'image_id', 'image_id',
'imageable_type', 'imageable_type',
'imageable_id', 'imageable_id',
]); ], 'imageable_unique');
}); });
} }
} }