简体   繁体   中英

Query execute in N+1 times

In my application i am using

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]}

code. When i run the code it executes N+1 times. I am sure this is the problem of N+1 query in rails. I need to simplify this code with out N+1.

Note : clinician_affiliation is belongs to provider_organization. (I am using Rails 2.3)

class Clinician
.....
has_many :provider_organizations, :through => :clinician_affiliations
...
end

From DB Physician and Provider_organizations are types of party table.

class Physician < Clinician

我认为这应该工作

Physician.find(:all, :include => :provider_organizations)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM