Forum: Ruby on Rails Paginate include => :last and order by value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7fb3901cce24ff7f9bd517ea92c898ae?d=identicon&s=25 Nathan (Guest)
on 2006-05-26 23:41
Why does it seem like I'm having so much trouble with this?

I created a topics table, and a replies table. In my Topic model I used
the following lines of code:

has_many :replies
has_one :first_reply, :class_name => 'Reply', :order => "created_on"
has_one :last_reply, :class_name => 'Reply', :order => "created_on DESC"

Thought I would be good at this point to paginate like so, where the
created_on value is in the replies table:

@topic_pages, @topics = paginate :topics, :per_page => 10, :include =>
:last_reply, :order => "created_on DESC"

This doesn't display all 10 topics though, for instance if the hottest
topic has more than 9 replies it will only show that one topic. Seems
that my code is pulling all of the replies for each topic from the
database instead of just the last one.

I don't think Active Record is taking into account my :has_one
declaration, any thoughts on how to fix this? Thank you.
This topic is locked and can not be replied to.