A more “rails” olution might be to do something like this:
@profiles = Profile.find :all, :include=>[:users],
:conditions=>[“users.idnot in(?)”, array_of_ids_of_users_to_skip]
This would result in two database hits, but it may perform better.
I would caution that subselects in the WHERE clause can be bad unless
database is smart enough to handle them. Some databases would execute
subselect once per every row in the table. (Where clauses are usually
for every row)
Again, this all depends on your database. You have a development.log
that shows you all the sql statements that the app runs. Take those and
them through your database’s query analyzer / explain plan.
This code is typed on the fly, not tested. You should be able to grasp
basic idea though. Let me know how it all goes.