Calling all comments for certain posts
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}], ...
精彩评论