我正在使用Rails 2.3.9應用程序,在這種情況下帖子是workouts
。我正在嘗試獲得以下所有comments
workouts
。打電話給某些帖子的所有評論
@workouts = Workout.today_only.all(:include => {:user => :memberships}, :conditions => ["workouts.public = '1' AND memberships.box_id = ?", @box.id], :order => "workouts.created_at DESC")
我的聯想是正確的:
Workout has_many :comments
Comment belongs_to :workout
我該如何獲得在對created_at DESC
下令那些specifc鍛鍊評論列表?
注意:today_only
是一個named_scope,如果它是相關的,我可以發佈代碼。
我建議創造那些條件更named_scopes和包括。現在你的代碼在同一行上有幾個抽象層次。 – kikito 2011-04-25 18:29:55
是的,我同意。只需要做到這一點。 – bgadoci 2011-04-26 02:24:15