Rails `NOT IN (null)` returning no results
I'm trying to retrieve some records and having an issue when one of my
parameters is an empty array. I understand why the query isn't returning
any results, but I don't know the best way of handling it within rails. In
my code, I'm calling
@user.trustees.where(["trustees.default = true AND trustees.id NOT IN
(?)", trustees.map{ |t| t.id }])
This works as expected when the trustees array actually contains objects,
however when it doesn't, the query returns nothing, as the SQL produced
results in
SELECT `users`.*
FROM `users`
INNER JOIN `trustees` ON `users`.`id` = `trustees`.`trustee_id`
WHERE `trustees`.`truster_id` = 1
AND (trustees.default = true
AND trustees.id NOT IN (NULL))
What's the easiest way of avoiding the NOT IN (NULL) issue that I'm having?
No comments:
Post a Comment