Closed MrThePlague closed 2 years ago
I think it makes sense to have a consistent handling here.
It might be worth starting by wrapping this array_map
(or extracting a new normaliseUuid
method or similar) in an array_filter
that uses Uuid::isValid
to remove any invalid UUIDs.
One thing you'll need to consider is the implications of that array being empty, as Post::whereUuid([])->first()
is undesirable.
One thing you'll need to consider is the implications of that array being empty, as Post::whereUuid([])->first() is undesirable.
Thanks for the reply! Are you able to help me understand why this would be undesirable? I think would have the desired effect, but I'm probably missing something.
Actually, perhaps it will work out ok. Once upon a time, this would have just returned the first record in the database.
Seems now it will run select * from <table> where 0 = 1
, so you shouldn't get any unexpected records back 👍
If using this package on a base Laravel application, a query using the
scopeWhereUuid
will returnnull
if regardless of whether theuuid
parameter(s) passed to it are valid UUIDs, which means that aModelNotFoundException
is returned when using thefindOrFail()
method. e.g.:MariaDB/MySQL base
However, if you're using the native
uuid
data type in Postgres, this instead returns a QueryException with either thefirst()
orfirstOrFail()
methods:PostgresSQL UUID
A similar behaviour exists if you're using the
EfficientUuid
, but instead you get annvalidUuidStringException
.MariaDB/MySQL w/ EfficientUuid
BindOnUuid
Normally this behaviour isn't a huge deal; however, when you're using the
BindsOnUuid
trait these last two examples return a500
, instead of what you'd (at least I'd?) expect, a404
.I'm happy to PR a quick
Uuid::isValid()
check into the Trait itself, but I wonder if it might be better to move that logic into the scope so that the*orFail()
methods work as intended? That being said, I'm not 100% sure what the best way of tackling the latter would be. Thoughts?