Hi Quick question (I think): I''ve got the table joins/active record stuff working I think, but is there a way I can order the query results? E.g. @post = Post.find(:all) @comments = @post.comments gives me all the comments on a particular post, but dated such that the first comment is first on the page. Could someone let me know how I can reverse that order so that it gives me the last comment first? Thanks - and sorry if it''s a stupid question Piers -- Posted via http://www.ruby-forum.com/.
Stephen Bartholomew
2006-Jun-08 17:06 UTC
[Rails] Re: Newbie question on ordering e.g. @post.comments
> Could someone let me know how I can reverse that order so that it gives > me the last comment first?You can just use the find() method: @post.comments.find(:all, :order => ''created_on DESC'') Steve -- Posted via http://www.ruby-forum.com/.
David Andersen
2006-Jun-08 17:08 UTC
[Rails] Re: Newbie question on ordering e.g. @post.comments
Yeh, or you could add the default order to the relationship, in the model like, has_many :comments, :order => "created_on desc" Stephen Bartholomew wrote:>> Could someone let me know how I can reverse that order so that it gives >> me the last comment first? >> > You can just use the find() method: > @post.comments.find(:all, :order => ''created_on DESC'') > > Steve > > >
Piers Young
2006-Jun-08 17:19 UTC
[Rails] Re: Newbie question on ordering e.g. @post.comments
Stephen Bartholomew wrote:>> Could someone let me know how I can reverse that order so that it gives >> me the last comment first? > You can just use the find() method: > @post.comments.find(:all, :order => ''created_on DESC'') > > SteveThanks Steve :) -- Posted via http://www.ruby-forum.com/.