39 líneas
1.0 KiB
PHP
39 líneas
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Album extends Model
|
|
{
|
|
|
|
public function artista(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Artista::class, 'ArtistId');
|
|
}
|
|
|
|
public function tracks(): HasMany
|
|
{
|
|
return $this->hasMany(Track::class, 'AlbumId');
|
|
}
|
|
|
|
|
|
protected $fillable = ['AlbumId', 'Title', 'ArtistId'];
|
|
|
|
|
|
protected $table = 'albums'; //Si la tabla no es la esperada, definimos la variable $table con el nombre correspondiente.
|
|
|
|
protected $primaryKey = 'AlbumId'; // Si la PK es distinta a id, definimos la variable $primaryKey con el nombre correcto.
|
|
|
|
public $incrementing = true; //true o false según si es o no autoincrementable la columna. Si se hace por trigger, definir
|
|
// en false.
|
|
|
|
//protected $keyType = 'string'; Si el tipo no es entero, definimos la variable $keyType
|
|
|
|
|
|
public $timestamps = false;
|
|
}
|
|
|
