I have this query, I have tried a few permutations to translate it into a :find equivalent, as a newbie this is a bit trickier than i first envisaged. heres the core sql: select resulttype from results where id in ( select result_id from outcomes o1 where o1.outcome_date = (select max(o2.outcome_date) from outcomes o2 where o2.testcase_id = o1.testcase_id and o1.testcase_id =''1'')); can you give me a few pointers, does it require a join clause from the results table to the outcomes, or can rails do this easier? -- 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 -~----------~----~----~----~------~----~------~--~---
Brad Symons wrote: Try @result = Resulttypes( :all, :conditions => [''id in ( select result_id from outcomes o1 where o1.outcome_date = (select max(o2.outcome_date) from outcomes o2 where o2.testcase_id = o1.testcase_id and o1.testcase_id =\''1\''))''] This should work, I am doing seomthing similiar only I am say ''NOT IN.'' -- 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 -~----------~----~----~----~------~----~------~--~---
i cannot get the brackets right, you seem to have more brackets on the ( than on the ), when i mess around with this it just throws all kinds of errors. here is another query i am trying to write using :find Result.find(:all, :conditions => ''resulttype = (select resulttype from results where id = 1)'') when i run this with debug <%= debug Result.find(:all, :conditions => ''resulttype = (select resulttype from results where id = 1)'') %> i get: resulttype = ''pass'' id = ''1'' but when i remove debuy, i just get ####, adding a h, like this <%= h Result.find(:all, :conditions => ''resulttype = (select resulttype from results where id = 1)'') %> i get #<Result:0x395f080> can anyone point me to a good source to understand more about the :find, because its quite obscure on the rails reference. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-06 15:57 UTC
Re: Need translation of sql query to :find equivalent
On 6 Oct 2008, at 16:41, Brad Symons wrote:>> when i run this with debug > > <%= debug Result.find(:all, :conditions => ''resulttype = (select > resulttype from results where id = 1)'') %> > > i get: > resulttype = ''pass'' > id = ''1'' > > but when i remove debuy, i just get ####, adding a h, like this > <%= h Result.find(:all, :conditions => ''resulttype = (select > resulttype > from results where id = 1)'') %> > > i get #<Result:0x395f080> ><%= %> just calls to_s on the result inside it. The to_s on an array is just the concatenation of the result of to_s on the elements of the array, and the default to_s on an AR object is unhelpful. It''s up to you do to something like <% @some_results.each do |result| date: <%= result.created_at %> value: <%= result.value %> ... <% end %>> can anyone point me to a good source to understand more about > the :find, > because its quite obscure on the rails reference. > > > -- > 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 -~----------~----~----~----~------~----~------~--~---