Currently I have a table of 10,000 users who I want to search. I also have another table of 3 users that I have approved. I want to make it so that the search result only returns 9997 of the users. In other words, if I have approved a user, I do not want them to appear in the search result. Here is what I have so far for the code:
approved_users = Approval.where(user_id: logged_in_user.id)
approved_user_ids = approved_users.map { |user| user.approved_user_id}
pre_search_results = User.find_by_sql("SELECT *
FROM users LEFT JOIN approvals
ON users.id = approvals.approved_user_id
WHERE name LIKE ? OR operator_id LIKE ?"
)
The first statement approved_users
returns this when I manually added 3 users:
id: 10, user_id: 39, approved_user_id: 37
id: 11, user_id: 39, approved_user_id: 35>,
id: 12, user_id: 39, approved_user_id: 41>
I then made approved_user_ids
just give me the id portion of the above statement, so it returns this:
[37, 35, 41]
Now, I want pre_search_results
to return me the 9997 other users and I have the above statement. It is currently returning nothing. Any ideas what can be done?