Description
I have the following objects:
final class DebugItem
{
public function __construct(
public int $id,
#[DateTimeFormat(FormatPattern::JAVASCRIPT)]
public DateTime $created_at,
public ?string $request_id,
public DebugItemType $type,
public string $data,
public Backtrace $backtrace,
) {}
}
final class Backtrace
{
/**
* @param Frame[] $frames
*/
public function __construct(
public array $frames = [],
) {}
}
final class Frame
{
public function __construct(
public string $file,
public int $line,
public ?string $method,
public ?string $class,
public array $arguments,
public mixed $instance,
public bool $vendor,
) {}
}
And I want to query them this way:
return query(DebugItem::class)
->select()
->orderBy('id DESC')
->where('id > :id', id: $lastSeenId)
->all();
This results in the ORM trying to query a non-existing backtrace_id
column on my debug_items
table:
SELECT
debug_items.id AS `debug_items.id`,
debug_items.created_at AS `debug_items.created_at`,
debug_items.request_id AS `debug_items.request_id`,
debug_items.type AS `debug_items.type`,
debug_items.data AS `debug_items.data`,
debug_items.backtrace_id AS `debug_items.backtrace_id`
FROM `debug_items`
ORDER BY id DESC
-- results in
-- SQLSTATE[HY000]: General error: 1 no such column: debug_items.backtrace_id
The migration looks like that:
return new CreateTableStatement('debug_items')
->primary()
->datetime('created_at')
->text('request_id', nullable: true)
->text('type')
->json('data')
->json('backtrace');