I have a model User thats has_many user_entitlements. I want to get all of the users that have a preview attribute and no user entitlements.
My code is currently:
User.where("preview is not null").keep_if {|user| user.user_entitlements.empty?}
This is iterating through all of the users and seeing if they have any user entitlements.
Is there a way I could do this in SQL to make it more efficient and avoid having to go through each user?