Ich habe ein User
Modell.Eager loading mit has_many durch
Ein user
hat viele integrations
.
Ein integration
wird ein profile
über integration_profiles
verbinden, die eine Spalte data
enthalten.
Ich möchte eifrig laden alle Benutzerprofile.
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
Ich versuchte dies: using enthält oder schließt sich
all = User.first.integrations.includes(:profiles)
Aber ich, wenn ich tat all.count
=> 2
Aber wenn ich
tunall = User.first.integrations.joins(:profiles)
all.count
=> the correct total
Sollte ich? Ich habe immer verwendet wird, schließt also nicht sicher, warum dies nicht funktioniert hier
hi @KirtiThorat, wie könnte ich rückwärts gehen und das gemeinsame Modell aufrufen oder auswählen, das Integrationen und Profile verbindet? –