I just found this ticket because I noticed the same issue. http://dev.rubyonrails.org/ticket/6251 The official response was that it''s not a bug because when you use :joins you are "riding close to the metal". But I''m at a loss as to figure out why this behavior even needs to exist. Every table (except HABTM links) in a typical Rails app is going to have an id column, so that means any JOIN by default is going to be clobbering ids. Most of the useful ad-hoc attributes that you would want to add to an query would have to be specified in the :select option anyway... how often do you just want to glom on all the attributes of some other table directly? A default of SELECT table_name.* in the presence of a :joins option just seems to make sense all around. Is there some benefit to always using SELECT * that warrants using it as the default even when it opens the door for such dangerous and unexpected behavior? At the very least the documentation for :joins should say "always specify :select or else..." -- Gabe da Silveira http://darwinweb.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> A default of SELECT table_name.* in the presence of a :joins option > just seems to make sense all around. Is there some benefit to always > using SELECT * that warrants using it as the default even when it > opens the door for such dangerous and unexpected behavior?That sounds like it could be a nice little patch, give it a try and reply here once it''s uploaded.> At the very least the documentation for :joins should say "always > specify :select or else..."Agreed, if you can''t get the solution above to work, send us a docs patch. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Alright, your wish is my command: http://dev.rubyonrails.org/ticket/8889 The solution is 1.5 lines, and I have a test included. Tested under mysql... not sure if the syntax can be assumed the way I did it for all cases... On 7/5/07, Michael Koziarski <michael@koziarski.com> wrote:> > > A default of SELECT table_name.* in the presence of a :joins option > > just seems to make sense all around. Is there some benefit to always > > using SELECT * that warrants using it as the default even when it > > opens the door for such dangerous and unexpected behavior? > > That sounds like it could be a nice little patch, give it a try and > reply here once it''s uploaded. > > > At the very least the documentation for :joins should say "always > > specify :select or else..." > > Agreed, if you can''t get the solution above to work, send us a docs patch. > > -- > Cheers > > Koz > > > >-- Gabe da Silveira http://darwinweb.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> http://dev.rubyonrails.org/ticket/8889 > > The solution is 1.5 lines, and I have a test included. Tested under > mysql... not sure if the syntax can be assumed the way I did it for > all cases... >I''ve applied the fix because I''ve also been bitten by this. But we''ll have to keep an eye out for surprising breakages in existing apps. Thanks! -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Great, thanks. If anything goes wrong I''ll definitely be around to add additional test cases and further tweaks if necessary. On 7/6/07, Michael Koziarski <michael@koziarski.com> wrote:> > > http://dev.rubyonrails.org/ticket/8889 > > > > The solution is 1.5 lines, and I have a test included. Tested under > > mysql... not sure if the syntax can be assumed the way I did it for > > all cases... > > > > I''ve applied the fix because I''ve also been bitten by this. But we''ll > have to keep an eye out for surprising breakages in existing apps. > > Thanks! > -- > Cheers > > Koz > > > >-- Gabe da Silveira http://darwinweb.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---