def user_type_name(%{user_type_id: nil}) do
from(sc in UserType, where: is_nil(sc.id), select: sc.name) |> Repo.one()
end
def user_type_name(%{user_type_id: user_type_id}) do
from(sc in UserType, where: sc.id == ^user_type_id, select: sc.name) |> Repo.one()
end
And expanding to what @iangl said, it is because in SQL using = comparator on NULL will return NULL which is falsey value. This mean that SELECT … WHERE x = NULL will return nothing, as the WHERE is always false.