I have two models Activities and Users
class Activity < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :activities
end
I can load all the activities which are associated with users by calling
User.all.includes(:activities)
But this actually pulls up all my activity objects from the database, which can cause performance problems as the table is quite large. My requirement is only to get the activity_ids associated
I can directly get that by executing the plain sql on the join table
select activity_id from activities_users where user_id in (...)
My question is: Can I do get the above functionality in a rails friendly way