I would like to do this: Greeter.find(:all, :select => "DISTINCT user_id", :include => [:user], :joins => [:user], :order => "users.nickname") But an error is always thrown, I either do the join so that I go order on the join table... which I have to do... or I do eager loading which helps out a lot with the efficiency of the page load time... but I can not do both it seems... or can I? -- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org Blog: http://www.kopanas.com Conference: http://www.cusec.net Twits: http://www.twitter.com/kopanas --~--~---------~--~----~------------~-------~--~----~ 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 22 Dec 2008, at 22:43, John Kopanas wrote:> > I would like to do this: > > Greeter.find(:all, :select => "DISTINCT user_id", :include => [:user], > :joins => [:user], :order => "users.nickname") > > But an error is always thrown, I either do the join so that I go > > order on the join table... which I have to do... or I do eager loading > which helps out a lot with the efficiency of the page load time... but > I can not do both it seems... or can I? >In such a case just the :include would create a join. Fred> > -- > John Kopanas > john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > Blog: http://www.kopanas.com > Conference: http://www.cusec.net > Twits: http://www.twitter.com/kopanas > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It would be nice to know what error gets thrown. I suspect it has something to do with using :select in a find where you also use :include, but I may be wrong. As far as I know, :select is ignored when you used :include. Another potential error is that you''re joining the users table twice: once on the :include (a left outer join), and once with the :joins (an inner join). The generated SQL would not contain aliases for the joined table, so it is specifying users twice. Is it your DBMS throwing the error? From the look of your :select, it seems like what you want back is User objects, not Greeter objects. If so, why are you querying using "Greeter.find", instead of "User.find"? This could probably be what you''re looking for: User.all(:joins => :greeter, :order => ''users.nickname'') #get all users who also are greeters. or Greeter.all(:include => :users, :order => ''users.nickname'') #get all greeters, and eager load the users. What is it? No idea! HTH, -H On Dec 22, 5:43 pm, "John Kopanas" <kopa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I would like to do this: > > Greeter.find(:all, :select => "DISTINCT user_id", :include => [:user], > :joins => [:user], :order => "users.nickname") > > But an error is always thrown, I either do the join so that I go > order on the join table... which I have to do... or I do eager loading > which helps out a lot with the efficiency of the page load time... but > I can not do both it seems... or can I? > > -- > John Kopanas > j...-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org > > Blog:http://www.kopanas.com > Conference:http://www.cusec.net > Twits:http://www.twitter.com/kopanas--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---