I am thinking about the best solution for a problem. Let\'s say that we have a list of ids of ActiveRecord model:
ids = [1, 100, 5, 30, 4, 2, 88, 44]
users_by_id = User.find(ids).index_by(&:id) # Gives you a hash indexed by ID ids.collect {|id| users_by_id[id] }