Hi, I have an app where users have friends, and friends can have messages for friends to see. I would like to list all the messages that my friends have easily. I can use @user_friends = current_user.friends to find all my friends and then I could loop through the friends to get each friend''s messages to place them in some array of messages I guess. But, is there a simpler way to get that list of messages? (I''m using has_many_friends plugin btw) Thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Message.all(:conditions => {:user_id => current_user.friends}) assuming the table messages has a column user_id. On Mar 15, 10:27 pm, comopasta Gr <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I have an app where users have friends, and friends can have messages > for friends to see. I would like to list all the messages that my > friends have easily. > > I can use @user_friends = current_user.friends to find all my friends > and then I could loop through the friends to get each friend''s messages > to place them in some array of messages I guess. > > But, is there a simpler way to get that list of messages? > > (I''m using has_many_friends plugin btw) > > Thanks. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Message.all(:conditions => {:user_id => current_user.friends})as i see it that would give you an error (as current_user.friends is an array not an integer). nonestly i''d do it with a loop. and why not? it''s easy and readable. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
"Wolas!" wrote:> Message.all(:conditions => {:user_id => current_user.friends}) > > assuming the table messages has a column user_id. > > > On Mar 15, 10:27�pm, comopasta Gr <rails-mailing-l...@andreas-s.net>Thanks Wolas, actually that worked fine :-) I''m a bit worried about the performance side of that request since there can be a huge number of messages and users. Of course user_id should be indexed in that table but I''m still worried. Any comments on the performance from anyone? Thanks. -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Any comments on the performance from anyone?Don''t worry about it until it''s a problem. YAGNI. But then again, you can do caching, paginate, intelligently use ajax to load only what''s needed, etc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Thanks Wolas, actually that worked fine :-)wow, i just learned something. ignore everything i said so far. i have to try that immediately... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I''m a bit worried about the performance side of that request since there > can be a huge number of messages and users. Of course user_id should be > indexed in that table but I''m still worried.this is still teh fastest way to do it since you are telling the db fetch all of these ids at once. Then again,> Don''t worry about it until it''s a problemis kinda the best advice in the matter if you add. "or untill you are finished, have done profiling and are bored of tv" On Mar 16, 9:31 pm, comopasta Gr <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> "Wolas!" wrote: > > Message.all(:conditions => {:user_id => current_user.friends}) > > > assuming the table messages has a column user_id. > > > On Mar 15, 10:27 pm, comopasta Gr <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Thanks Wolas, actually that worked fine :-) > I''m a bit worried about the performance side of that request since there > can be a huge number of messages and users. Of course user_id should be > indexed in that table but I''m still worried. > > Any comments on the performance from anyone? > > Thanks. > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---