Hi all, I have a big problem. I am displaying a list of articles which displays the title of the article and the author''s name. The problem is that :select option seems to be incompatible with :include. When I do not include author Article.find(:all, :select=>"articles.title, articles.id, articles.author_id"), it only selects the title as expected, but it has to do an additional query for every author. However, if I run Article.find(:all, :select=>"articles.title, articles.id, articles.author_id", :include=>:author) It still selects every field from articles and authors... Why? Thank you! -- 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 -~----------~----~----~----~------~----~------~--~---
Nauhaie None wrote:> Hi all, > > I have a big problem. I am displaying a list of articles which displays > the title of the article and the author''s name. > > The problem is that :select option seems to be incompatible with > :include. When I do not include author > > Article.find(:all, :select=>"articles.title, articles.id, > articles.author_id"), it only selects the title as expected, but it has > to do an additional query for every author. > > However, if I run > > Article.find(:all, :select=>"articles.title, articles.id, > articles.author_id", :include=>:author) > > It still selects every field from articles and authors... Why?Use of eager loading causes a special select to be used so that the joined table can be separated into a hierarchy of models. Is efficiency the only reason you want to limit your select set? If so, you''d have to write this to pull the author name into the fetched article models: Article.find( :all, :select => ''articles.id, articles.title, authors.name as author_name'', :joins => ''left join authors on authors.id = articles.author_id'' ) -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Great! Thank you!! -- 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 -~----------~----~----~----~------~----~------~--~---