refactor(website): update relationships and migration to use 'website_type_code' instead of 'website_type'

This commit is contained in:
2026-07-29 15:03:31 -03:00
parent b9ad2e589f
commit 9e3163b74f
4 changed files with 9 additions and 7 deletions

View File

@@ -22,7 +22,7 @@ class WebsiteType extends Model
*/
public function extras(): HasMany
{
return $this->hasMany(WebsiteTypeExtra::class, 'website_type');
return $this->hasMany(WebsiteTypeExtra::class, 'website_type_code', 'codigo');
}
/**

View File

@@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable([
'website_type',
'website_type_code',
'nombre',
'descripcion',
'is_required',
@@ -27,7 +27,6 @@ class WebsiteTypeExtra extends Model
protected function casts(): array
{
return [
'website_type' => 'integer',
'is_required' => 'boolean',
'config_schema' => 'array',
];
@@ -38,7 +37,7 @@ class WebsiteTypeExtra extends Model
*/
public function websiteType(): BelongsTo
{
return $this->belongsTo(WebsiteType::class, 'website_type');
return $this->belongsTo(WebsiteType::class, 'website_type_code', 'codigo');
}
/**

View File

@@ -27,8 +27,10 @@ return new class extends Migration
Schema::create('website_type_extras', function (Blueprint $table): void {
$table->id();
$table->foreignId('website_type')
->constrained('website_type')
$table->string('website_type_code');
$table->foreign('website_type_code')
->references('codigo')
->on('website_type')
->cascadeOnUpdate()
->cascadeOnDelete();
$table->string('nombre');

View File

@@ -26,7 +26,7 @@ class WebsiteExtrasTest extends TestCase
$this->assertEqualsCanonicalizing([
'id',
'website_type',
'website_type_code',
'nombre',
'descripcion',
'is_required',
@@ -68,6 +68,7 @@ class WebsiteExtrasTest extends TestCase
]);
$this->assertTrue($type->extras()->firstOrFail()->is($typeExtra));
$this->assertSame($type->codigo, $typeExtra->website_type_code);
$this->assertTrue($type->tenants()->firstOrFail()->is($tenant));
$this->assertTrue($tenant->websiteType()->firstOrFail()->is($type));
$this->assertSame($type->codigo, $tenant->website_type_code);