Hi. Is there a way to stop rails from tokenizing a mysql query? I have an association where I need to change :select to: :select => "*, (select count(something_id) from second_table where second_table.something_id = main_table.id ) as count" It works OK without loading associations, however I need to add an :include. At that point all the select is changed and it says ''count'' does not exist. How can this made to work? -- M. --~--~---------~--~----~------------~-------~--~----~ 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 19:07, Marcelo Barbudas wrote:> > Hi. > > Is there a way to stop rails from tokenizing a mysql query? I have an > association where I need to change :select to: > > :select => "*, (select count(something_id) from second_table where > second_table.something_id = main_table.id ) as count" > > It works OK without loading associations, however I need to add > an :include. At that point all the select is changed and it says > ''count'' does not exist.> How can this made to work?It can''t. joins based :include overwrites the select. The non joined based include doesn''t but rails won''t use it because it sees you referencing tables other than the main table in the query (and isn''t smart enough to work out that it''s ok because it''s just a subselect). Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Have you tried using the :joins key and manually specifying your joins? On Dec 22, 5:39 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 22 Dec 2008, at 19:07, Marcelo Barbudas wrote: > > > > > Hi. > > > Is there a way to stop rails from tokenizing a mysql query? I have an > > association where I need to change :select to: > > > :select => "*, (select count(something_id) from second_table where > > second_table.something_id = main_table.id ) as count" > > > It works OK without loading associations, however I need to add > > an :include. At that point all the select is changed and it says > > ''count'' does not exist. > > How can this made to work? > > It can''t. joins based :include overwrites the select. The non joined > based include doesn''t but rails won''t use it because it sees you > referencing tables other than the main table in the query (and isn''t > smart enough to work out that it''s ok because it''s just a subselect). > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 23 Dec 2008, at 21:43, TomRossi7 wrote:> > Have you tried using the :joins key and manually specifying your > joins? >It depends on what you''re trying to achieve. If you want to eager load stuff the :joins won''t do it. If you just want to join some tables because you need them for your conditions etc... then :joins is exactly what is needed. Fred> On Dec 22, 5:39 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 22 Dec 2008, at 19:07, Marcelo Barbudas wrote: >> >> >> >>> Hi. >> >>> Is there a way to stop rails from tokenizing a mysql query? I have >>> an >>> association where I need to change :select to: >> >>> :select => "*, (select count(something_id) from second_table where >>> second_table.something_id = main_table.id ) as count" >> >>> It works OK without loading associations, however I need to add >>> an :include. At that point all the select is changed and it says >>> ''count'' does not exist. >>> How can this made to work? >> >> It can''t. joins based :include overwrites the select. The non joined >> based include doesn''t but rails won''t use it because it sees you >> referencing tables other than the main table in the query (and isn''t >> smart enough to work out that it''s ok because it''s just a subselect). >> >> Fred > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---