I couldn’t find an answer to this from searching so thought I would make a post about it.
I’m trying to get a list of Users who have not created Office Hours. Essentially, records where the association does not exist or the count is 0.
This article helped but was too advanced for what I’m doing.
The suggestion is to user LEFT OUTER JOIN.
SELECT * FROM rentals LEFT OUTER JOIN unavailabilities ON (unavailabilities.rental_id = rentals.id) WHERE rental_id IS NULL;
Converting this to my use case in Elixir leads to:
query = from u in User, left_join: o in OfficeHour, on: [o.user_id: u.id], where: user_id == nil
I’m not sure if this is correct, or what would be the way to write this using the pipe operators? Any help is appreciated.