开发者

Calling all comments for certain posts

开发者 https://www.devze.com 2023-02-28 19:38 出处:网络
I am working with a Rails 2.3.9 application and in this case posts are workouts. I am trying to get all comments for the following workouts.

I am working with a Rails 2.3.9 application and in this case posts are workouts. I am trying to get all comments for the following workouts.

@workouts = Workout.today_only.all(:include => {:user => :memberships}, :conditions => ["workouts.public = '1' AND memberships.box_id = ?", @box.id], :order => "workouts.created_at DESC")

My associations a开发者_开发知识库re correct:

Workout has_many :comments
Comment belongs_to :workout

How would I get at list of comments on those specifc workouts ordered by created_at DESC?

Note: today_only is a named_scope and I can post the code if it is relevant.


In your Workout model, add:

has_many :comments, :order => 'created_at DESC'

then you can do:

Workout.today_only.all(:include => [:comments, {:user => :memberships}], ...
0

精彩评论

暂无评论...
验证码 换一张
取 消