我正在使用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
订购的那些特定训练的评论列表?
注意:today_only
是一个named_scope,如果相关,我可以发布代码。
答案 0 :(得分:0)
在您的锻炼模型中,添加:
has_many :comments, :order => 'created_at DESC'
然后你可以这样做:
Workout.today_only.all(:include => [:comments, {:user => :memberships}], ...