I've got:

User
has_many :reviews

Review
belongs_to :user
belongs_to :album

Album
has_many :reviews

Some background:

The front page of my site contains for reviews. Currently, these are
the four most recent reviews in the system. However, if I submit a
review in the morning, and someone goes and submits 4 reviews at
lunch, I get bumped off the front page. What I'd like to do is group
the reviews by user so that the front page only displays one review --
the most recent -- per user. It follows that if my review 4th on the
front page (the oldest), and I submit a new review, I will get bumped
to 1st on the front page with my new review showing.

So originally, my finder was:
    @recent_reviews = Review.find(:all, :order => "created_at
DESC", :limit => 4)

I tried modifying it to:
    @recent_reviews = Review.find(:all, :order => "reviews.created_at
DESC", :group => "user_id", :limit => 4)

But it behaved strangely. My front page only contained one review per
user, as expected, however, the order was not what I expected. With
the latter finder, the system seems to take the first four reviews
created by the users with the most recent _first_ review, if you
follow.

So does anyone know what I'm doing wrong and how I can accomplish this
sort of sorting in the database? Is it even possible? Or am I looking
at some sorting in the ruby code itself. How might you accomplish
this?

Thanks to anyone and everyone who can lend a hand.

_john

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to