Fix export of records with a string primary key #276
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing information
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
pxlrbt/filament-excel!276
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/uuid-primary-key-export"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #189.
Cause
getQuery()picked the query strategy from the model's declared$keyType:whereIntegerInRaw()casts every value with(int)and inlines it as a raw literal instead of a binding (Builder.php:1458). So for a model with$primaryKey = 'uuid'that never declared$keyType = 'string',getKeyType()returns the default'int', every UUID is cast to0, and you get exactly the SQL from the issue:On MySQL there is no error at all — it just silently exports zero rows, which is the nastier half of this bug.
Laravel's
HasUuidssets$keyTypefor you, which is why this only bites hand-rolled string keys.Fix
Decide from the actual key values rather than the declared type. The raw-integer fast path (worth keeping — it avoids thousands of bindings on large "select all" exports) is only taken when every selected key really is an integer; anything else falls back to
whereIn()with bindings.Verified
Against a real SQLite-backed model with
$primaryKey = 'uuid'and no$keyType:in (0)in (1, 2, 3)— fast path intactClosing this. Laravel core's own
whereKey()pickswhereIntegerInRaw()off$keyTypethe exact same way, so this package was following the framework convention — the model in #189 is simply missingprotected $keyType = 'string';and is equally broken in core (Model::find([$uuid])produces the same SQL). Not worth diverging from Laravel here.Pull request closed