Mam model User
.Chętne ładowanie z has_many przez
A user
ma wiele integrations
.
An jest dołączone do profile
przez integration_profiles
, który zawiera kolumnę data
.
Chcę bardzo szybko załadować wszystkie profile użytkownika.
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
Próbowałem to:
all = User.first.integrations.includes(:profiles)
Ale kiedy zrobiłem all.count
=> 2
Ale kiedy zrobić
all = User.first.integrations.joins(:profiles)
all.count
=> the correct total
powinienem być przy użyciu obejmuje lub łączy? Ja zawsze obejmuje więc nie wiem, dlaczego to nie działa tutaj
hi @KirtiThorat, jak mógłbym cofnąć się i zadzwonić lub wybrać wspólny model, który łączy integrację i profile? –