fix(database): resolve uuid primary keys from positional insert bindings - #2301
radoslav-grencik wants to merge 4 commits into
Conversation
…n keys Iterable inserts (`insert()` with array data) never generated `#[Uuid]` primary keys — only the object path (`create()`, `save()`) did — so UUID models inserted this way ended up with a NULL key (error 1364 on MySQL). Migrations also had no way to define UUID-typed foreign key columns: `belongsTo()`/`foreignId()` always compile INTEGER, which cannot reference a UUID primary key (fails on PostgreSQL). - generate `#[Uuid]` values in the iterable insert path when the key is absent (explicitly provided ids are never overwritten) - add `uuidColumn()`, `belongsToUuid()` and `foreignUuid()` to `CreateTableStatement` (CHAR(36) / UUID / TEXT per dialect)
Benchmark ResultsComparison of Open to see the benchmark results
Generated by phpbench against commit dbe65d6 |
What this PR doesFixes relation auto-inserts for models with 1. Bug fix:
|
|
What happens when an insert explicitly passes a |
Good catch — that was a bug. When an insert explicitly passes MySQL and PostgreSQL both treat Fix: treat $value = $query->bindings[$index] ?? null;
// 0 is treated as "auto-increment" by MySQL/PostgreSQL — not a real id.
if ($value === 0 || $value === null) {
return null;
}
return $value;This is safe for UUID models too — a UUID entry never contains Added a test ( |
Fixes #2300