Random Guy Random Guy - 7 months ago 33
Ruby Question

How do I find the set of values that are present in one database but not in another?

There are 2 tables : User and Teacher. Teacher.user_id is from User. So, how do I find in a single query, all the users who are not in teachers.

I meant something along the lines :



You can use where.not query from ActiveRecord try something like below:

User.where.not(id: Teacher.pluck(:user_id).reject {|x| x.nil?})

Note: used reject method, in case you have nil values in some records.