hi all, My relationships: - group habtm user and - user has_many events :through statistics. The statistics contains the id of user and is of event and additional data. How can I get all the users in a group with their statistics via eager loading. I tried: @users = a_node.users.find(:all, :include => :statistics, :conditions => ["statistics.event_id = ?", event.id]) The problem is that I only get the users with a statistics record and I also want users without any stastics. I think the problem is caused by :conditions => ["statistics.event_id = ?", event.id] but I don''t know how to include the event_id in another way. Someone can help me out? Thanks -Stijn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi all, My relationships: - group habtm user and - user has_many events :through statistics. The statistics contains the id of user and is of event and additional data. How can I get all the users in a group with their statistics via eager loading. I tried: @users = a_node.users.find(:all, :include => :statistics, :conditions => ["statistics.event_id = ?", event.id]) The problem is that I only get the users with a statistics record and I also want users without any stastics. I think the problem is caused by :conditions => ["statistics.event_id = ?", event.id] but I don''t know how to include the event_id in another way. Someone can help me out? Thanks -Stijn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
:include => [:statistics, :events] or :include => ":statistics, :events" No? On Jan 30, 2008 9:28 AM, Tarscher <tarscher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hi all, > > My relationships: > - group habtm user and > - user has_many events :through statistics. > The statistics contains the id of user and is of event and additional > data. > > How can I get all the users in a group with their statistics via eager > loading. > > I tried: > @users = a_node.users.find(:all, :include => :statistics, :conditions > => ["statistics.event_id = ?", event.id]) > > The problem is that I only get the users with a statistics record and > I also want users without any stastics. I think the problem is caused > by :conditions => ["statistics.event_id = ?", event.id] but I don''t > know how to include the event_id in another way. > > Someone can help me out? > > Thanks > -Stijn > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> The problem is that I only get the users with a statistics record and > I also want users without any stastics. I think the problem is caused > by :conditions => ["statistics.event_id = ?", event.id] but I don''t > know how to include the event_id in another way. > > Someone can help me out? > > Thanks > -StijnTry using the :joins parameter and manually join to the statistics table with an OUTER join, or use the find_by_sql method if you have to. The joins param value will be something like :joins => "left outer join statistics s on s.user_id = user.id" Having the left outer join should still allow you to filter the the statistics with the event_id and include the users with and without stats. -- 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 -~----------~----~----~----~------~----~------~--~---