在我的应用程序中,我正在使用
phy = Physician.find(:all, :include => {:clinician_affiliations => :provider_organization}, :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}
代码。当我运行代码时,它执行N + 1次。我确信这是rails中N + 1查询的问题。我需要用N + 1来简化这段代码。
注意:clinician_affiliation属于provider_organization。 (我使用的是Rails 2.3)
class Clinician
.....
has_many :provider_organizations, :through => :clinician_affiliations
...
end
来自DB Physician和Provider_organizations是聚会表的类型。
class Physician<临床医生
答案 0 :(得分:1)
我认为这应该有用
Physician.find(:all, :include => :provider_organizations)