Hi, I have user table (last_activity, last_activity_at, ....) and friendships table (many to many). What I am trying to do is to show to the user the last actions of his/her friends. [code]@activities = User.find_by_username(username, :order => ''last_activity_at DESC'', :include => [:friendships => :friend])[/code] [code]<%= render :partial => ''friends_activity'', :collection => @activities.friendships %>[/code] But the descending ordering is not working :( What I am missing here? Cheers, Pete -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1 Dec 2008, at 08:48, Petr Bobek wrote:> > Hi, > > I have user table (last_activity, last_activity_at, ....) and > friendships table (many to many). > What I am trying to do is to show to the user the last actions of > his/her friends. > > [code]@activities = User.find_by_username(username, :order => > ''last_activity_at DESC'', :include => [:friendships => :friend])[/code] > > [code]<%= render :partial => ''friends_activity'', :collection => > @activities.friendships %>[/code] > > But the descending ordering is not working :( What I am missing here? > Cheers, PeteThat 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> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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) > > FredOhh 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 1, 9:47 am, Petr Bobek <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 ? CheersThe 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I''d write the above query like this: > u = User.find_by_username ... > u.friendships.find :all, :joins => :friends, :order => > ''last_activity_at desc''Cheers Fred, this is the trick I was looking for. Petr -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---