On Dec 1, 9:47 am, Petr Bobek <[EMAIL PROTECTED]>
wrote:
> > That sort would have ordered the users (from the 'main' find) by
> > descending last_activity_at, not the associations (which are loaded
> > with a separate find)
>
> > Fred
>
> Ohh I see, I was trying to sort friendships table, but there is no
> column last_activity_at. I guess that's it. :( or is there a way to
> re-sort the data by last_activity_at ? Cheers

The old style include that did one big join would probably do that for
you.
Just to be sure  - I'm assuming that friendships and friends are a
self referential has many though relationship (ie back to users ?)

I'd write the above query like this:
u = User.find_by_username ...
u.friendships.find :all, :joins => :friends, :order =>
'last_activity_at desc'

You could squish that down to one query, but you'll have to work out
how it aliases the table names (I always have to look that one up)

Fred
--~--~---------~--~----~------------~-------~--~----~
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