I have an sql with some inputs,notably a date. For that date I run the sql and get a result @result = Model.find_by_sql(sql) What I want is to have eight versions of this (different dates in the sql) and then combine all the results and pass them back once to the view. Is that possible? --~--~---------~--~----~------------~-------~--~----~ 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 Jul 24, 8:09 am, Jorg Lueke <jlueke_2...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> I have an sql with some inputs,notably a date. For that date I run > the sql and get a result > > @result = Model.find_by_sql(sql) > > What I want is to have eight versions of this (different dates in the > sql) and then combine all the results and pass them back once to the > view. Is that possible?Yes it is --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If you can come up w/SQL that will return > 1 record, find_by_sql (like all the other find* methods) should return an array of instances of your model w/out any extra work on your part. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Jorg Lueke Sent: Thursday, July 24, 2008 7:22 AM To: Ruby on Rails: Talk Subject: [Rails] Re: Can Two Active Record Results be Added? On Jul 24, 8:09 am, Jorg Lueke <jlueke_2...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> I have an sql with some inputs,notably a date. For that date I run > the sql and get a result > > @result = Model.find_by_sql(sql) > > What I want is to have eight versions of this (different dates in the > sql) and then combine all the results and pass them back once to the > view. Is that possible?Yes it is --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In this case that would be a lot harder than creating the instances multiple times and adding them together. Though it''s likely more efficient to do it all on the backend, doing procedural logic in SQL isn''t very clean. If ActiveRecord supported stored procs it would make it easier. Of course some people think all logic, even data logic,belongs outside the data layer. On Jul 24, 12:13 pm, "Pardee, Roy" <parde...-go57ItdSaco@public.gmane.org> wrote:> If you can come up w/SQL that will return > 1 record, find_by_sql (like all the other find* methods) should return an array of instances of your model w/out any extra work on your part. > > > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Jorg Lueke > Sent: Thursday, July 24, 2008 7:22 AM > To: Ruby on Rails: Talk > Subject: [Rails] Re: Can Two Active Record Results be Added? > > On Jul 24, 8:09 am, Jorg Lueke <jlueke_2...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > I have an sql with some inputs,notably a date. For that date I run > > the sql and get a result > > > @result = Model.find_by_sql(sql) > > > What I want is to have eight versions of this (different dates in the > > sql) and then combine all the results and pass them back once to the > > view. Is that possible? > > Yes it is- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Huh--can you not pass a "exec my_cool_sproc" to find_by_sql? But if you''ve just got a set of dates to cycle through, can''t you just stash those in an in() list? In fact, I wouldn''t be surprised if you could just pass an array of DateTimes to Model.find_by_my_date_field. I know the plain Model.find will take an array of IDs... -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Jorg Lueke Sent: Thursday, July 24, 2008 10:21 AM To: Ruby on Rails: Talk Subject: [Rails] Re: Can Two Active Record Results be Added? In this case that would be a lot harder than creating the instances multiple times and adding them together. Though it''s likely more efficient to do it all on the backend, doing procedural logic in SQL isn''t very clean. If ActiveRecord supported stored procs it would make it easier. Of course some people think all logic, even data logic,belongs outside the data layer. On Jul 24, 12:13 pm, "Pardee, Roy" <parde...-go57ItdSaco@public.gmane.org> wrote:> If you can come up w/SQL that will return > 1 record, find_by_sql (like all the other find* methods) should return an array of instances of your model w/out any extra work on your part. > > > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Jorg Lueke > Sent: Thursday, July 24, 2008 7:22 AM > To: Ruby on Rails: Talk > Subject: [Rails] Re: Can Two Active Record Results be Added? > > On Jul 24, 8:09 am, Jorg Lueke <jlueke_2...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > I have an sql with some inputs,notably a date. For that date I run > > the sql and get a result > > > @result = Model.find_by_sql(sql) > > > What I want is to have eight versions of this (different dates in > > the > > sql) and then combine all the results and pass them back once to the > > view. Is that possible? > > Yes it is- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---