Hi there. Is there a bug in 1.2 anyone knows of that generates faulty sql? I have @jobs = Recommendation.find(:all, :conditions => ["job_id = ?", "#{params[:id]}%"], :group => ''job_id'',:select => [:tracker, :job_id]) but it generates SELECT trackerjob_id FROM recommendations WHERE (job_id = ''3%'') GROUP BY job_id see? it leaves out the comma in the selected columns. Did anyone see this before? Is there a fix for it? Thanks people! Marco -- 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 -~----------~----~----~----~------~----~------~--~---
that''s because :select expects a string, not an array. the array is getting converted to a string and that is the result irb(main):001:0> [:tracker, :job_id].to_s => "trackerjob_id" so you want :select => "tracker, job_id" also, your condition is a bit strange. is job_id an integer column? why are you using = and %? you want every record where job_id begins with 3? On 3/8/07, Marco Kotrotsos <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi there. > > Is there a bug in 1.2 anyone knows of that generates faulty sql? > > I have > > @jobs = Recommendation.find(:all, :conditions => ["job_id = ?", > "#{params[:id]}%"], :group => ''job_id'',:select => [:tracker, :job_id]) > > but it generates > > SELECT trackerjob_id FROM recommendations WHERE (job_id = ''3%'') GROUP BY > job_id > > see? it leaves out the comma in the selected columns. > > Did anyone see this before? Is there a fix for it? > > Thanks people! > Marco > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> that''s because :select expects a string, not an array. the array is > getting converted to a string and that is the result > > irb(main):001:0> [:tracker, :job_id].to_s > => "trackerjob_id" > > so you want > > :select => "tracker, job_id" > > also, your condition is a bit strange. > > is job_id an integer column? why are you using = and %? you want > every record where job_id begins with 3?Ye I know, i fixed the sql- also it was just mostly dummy sql to show the point (the % was an typo) So I guess O''Reilly''s Quick reference in ''Ruby on Rails up and running'' on page 145 is wrong. it clearly stated :select => [:name, :adress] or should i have just read it "name, adress" ? Thank alot! Marco -- 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 -~----------~----~----~----~------~----~------~--~---
if you are passing in [:x, :y] and getting back "xy" then that means the array is being converted to a string. pass it a string. from the api :select: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not include the joined columns. from the source def construct_finder_sql(options) scope = scope(:find) sql = "SELECT #{(scope && scope[:select]) || options[:select] || ''*''} " so as you can see, options[:select] in the above "#{[:a, :b]}" => "ab" On 3/9/07, Marco Kotrotsos <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Chris Hall wrote: > > that''s because :select expects a string, not an array. the array is > > getting converted to a string and that is the result > > > > irb(main):001:0> [:tracker, :job_id].to_s > > => "trackerjob_id" > > > > so you want > > > > :select => "tracker, job_id" > > > > also, your condition is a bit strange. > > > > is job_id an integer column? why are you using = and %? you want > > every record where job_id begins with 3? > > Ye I know, i fixed the sql- also it was just mostly dummy sql to show > the point (the % was an typo) > So I guess O''Reilly''s Quick reference in ''Ruby on Rails up and running'' > on page 145 is wrong. it clearly stated > > :select => [:name, :adress] > > or should i have just read it "name, adress" ? > Thank alot! > Marco > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks Chris, this as been most helpfull kind regards, Marco Chris Hall wrote:> if you are passing in [:x, :y] and getting back "xy" then that means > the array is being converted to a string. pass it a string. > > from the api > > :select: By default, this is * as in SELECT * FROM, but can be changed > if you for example want to do a join, but not include the joined > columns. > > from the source > > def construct_finder_sql(options) > scope = scope(:find) > sql = "SELECT #{(scope && scope[:select]) || > options[:select] || ''*''} " > > so as you can see, options[:select] in the above > > "#{[:a, :b]}" => "ab"-- 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 -~----------~----~----~----~------~----~------~--~---