2013-06-28 34 views

回答

0

你必須定義一個自定義關聯而不是範圍,並將其用於熱切加載:

has_many :more_no_comments, :class_name => 'Comment', -> { where "no_times > 10" } 

然後

User.includes(:more_no_comments).all.collect{|u| u.comments.more_no_comments} 

this question

+0

爲什麼這不能沒有自定義關聯? –

+0

'includes'適用於模型的關聯,範圍在* associated *模型上定義 –

相關問題