-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hello, thank you for your work on this excellent library! There's just this one annoying case that keeps coming up ever since we started using it. Here's an example of where it might happen:
$user_ids = getUserIdsByAccountId($account_id);
$settings = getSettingsByUserIds($user_ids);
function getSettingsByUserIds(array $user_ids): array {
return Select::new($conn)
->columns('*')
->from('settings')
->whereEquals(['user_id' => $user_ids])
->fetchAll();
}This causes an SQL syntax error if there happens to be no users in that account (i.e. $user_ids is an empty array). It produces the query SELECT * FROM settings WHERE user_id IN ().
So we have to keep writing lines like if ($user_ids === []) { return []; } everywhere to handle this case.
I'm wondering if it would make sense for Atlas to handle this case by mapping it to a false condition: SELECT * FROM settings WHERE false? Then no rows are returned, which to me is the expected result of an empty array condition. You could also see it as making up for a shortcoming in SQL's syntax.
What do you think? (Sorry if this has already been considered before.)