I have a User
model.
A user
has many integrations
.
An integration
is join to a profile
via integration_profiles
which contains a column data
.
I want to eager load all of a user's profiles.
class Integration < ActiveRecord::Base
has_many :integration_profiles
has_many :profiles, through: :integration_profiles
end
class IntegrationProfile < ActiveRecord::Base
belongs_to :integration
belongs_to :profile
end
class Profile < ActiveRecord::Base
has_many :integration_profiles
has_many :integrations, through: :integration_profiles
end
I tried this:
all = User.first.integrations.includes(:profiles)
But I when I did all.count
=> 2
But when I do
all = User.first.integrations.joins(:profiles)
all.count
=> the correct total
Should I be using includes or joins? I have always used includes so not sure why this isn't working here