fix(repository): hydrate enum columns instead of failing on read
Tests / PHP 8.4 (push) Failing after 4m31s
Tests / PHP 8.4 (push) Failing after 4m31s
Repository::castDatabaseValue() called TypeCaster::cast() with the enum's class name as the "type", so any row of a model declaring #[Enum] threw "Cannot assign string to property X of type Y" the moment it was read. Writes worked, which is why this survived 1.0.0: the select path is only exercised on read. castDatabaseValue() now delegates to TypeCaster::castEnum() when the property declares one, and keeps the null passthrough. Covered by EnumHydrationTest with a scalar value and a null.
This commit is contained in:
1 parent
a655a6f3ae
commit
4faad2c46e
3 files changed
+77
No files matched your search
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Camelia\Orm\Tests\Fixture;
|
||||
|
||||
use Camelia\Orm\Attribute\AutoIncrement;
|
||||
use Camelia\Orm\Attribute\Enum;
|
||||
use Camelia\Orm\Attribute\PrimaryKey;
|
||||
use Camelia\Orm\Attribute\TableName;
|
||||
use Camelia\Orm\Model;
|
||||
|
||||
enum EstadoArticulo: string
|
||||
{
|
||||
case Borrador = 'borrador';
|
||||
case Publicado = 'publicado';
|
||||
}
|
||||
|
||||
#[TableName('articulos_estado')]
|
||||
final class ArticuloConEstado extends Model
|
||||
{
|
||||
#[PrimaryKey, AutoIncrement]
|
||||
public ?int $codigo = null;
|
||||
|
||||
public string $nombre = '';
|
||||
|
||||
#[Enum(EstadoArticulo::class)]
|
||||
public ?EstadoArticulo $estado = EstadoArticulo::Borrador;
|
||||
}
|
||||
Reference in new issue
Block a user