It's usually a bad idea to use string ids. Be aware it will slow down your database as your indexing for strings is way slower.
Nov 13, 2022
8
Level 3
ManyToMany and string Ids
Has anyone faced problems with Many to many relations and non Int ids?
I tried the example in the documentation page using char instead of int for ids to verify this in case my code had errors
here is the query using INT ids for user with id 3
SELECT `roles`.*,
`user_roles`.`user_id` AS `pivot_user_id`,
`user_roles`.`role_id` AS `pivot_role_id`
FROM `test_categories`
INNER JOIN `user_roles` ON `roles`.`id` = `user_roles`.`role_id`
WHERE `user_roles`.`user_id` in (3)
if i have string iDs for example user_3
SELECT `roles`.*,
`user_roles`.`user_id` AS `pivot_user_id`,
`user_roles`.`role_id` AS `pivot_role_id`
FROM `test_categories`
INNER JOIN `user_roles` ON `roles`.`id` = `user_roles`.`role_id`
WHERE `user_roles`.`user_id` in (0)
the last where clause does not use the appropriate id, it is 0 instead of user_3
Level 102
@ederson set key type as string as well
protected $keyType = 'string';
Please or to participate in this conversation.