I''d like to write a data import script as a rake task. It would execute a moderately complex query against some legacy tables returning a recordset. I''d like to get the results of that recordset into the rake task and iterate over it creating instances of ActiveRecord derived models. --~--~---------~--~----~------------~-------~--~----~ 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 8, 11:38 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to write a data import script as a rake task. It would > execute a moderately complex query against some legacy tables > returning a recordset. I''d like to get the results of that recordset > into the rake task and iterate over it creating instances of > ActiveRecord derived models.Seems reasonable enough, but what''s the question you''re asking ? 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 Jul 9, 5:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 8, 11:38 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''d like to write a data import script as a rake task. It would > > execute a moderately complex query against some legacy tables > > returning a recordset. I''d like to get the results of that recordset > > into the rake task and iterate over it creating instances of > > ActiveRecord derived models. > > Seems reasonable enough, but what''s the question you''re asking ? >I''d like to know how to do the first part. How do I execute a non- CRUD query against the legacy tables and receive a recordset of those results? There''s currently no ActiveRecord derived model in place for the legacy tables. --~--~---------~--~----~------------~-------~--~----~ 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 9 Jul 2008, at 15:23, Jobu wrote:> > On Jul 9, 5:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Jul 8, 11:38 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> I''d like to write a data import script as a rake task. It would >>> execute a moderately complex query against some legacy tables >>> returning a recordset. I''d like to get the results of that >>> recordset >>> into the rake task and iterate over it creating instances of >>> ActiveRecord derived models. >> >> Seems reasonable enough, but what''s the question you''re asking ? >> > > I''d like to know how to do the first part. How do I execute a non- > CRUD query against the legacy tables and receive a recordset of those > results? There''s currently no ActiveRecord derived model in place for > the legacy tables.Have you played with ActiveRecord::Base.connection.select_all ? 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 -~----------~----~----~----~------~----~------~--~---
On Jul 9, 2008, at 10:23 AM, Jobu wrote:> On Jul 9, 5:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Jul 8, 11:38 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> I''d like to write a data import script as a rake task. It would >>> execute a moderately complex query against some legacy tables >>> returning a recordset. I''d like to get the results of that >>> recordset >>> into the rake task and iterate over it creating instances of >>> ActiveRecord derived models. >> >> Seems reasonable enough, but what''s the question you''re asking ? >> > > I''d like to know how to do the first part. How do I execute a non- > CRUD query against the legacy tables and receive a recordset of those > results? There''s currently no ActiveRecord derived model in place for > the legacy tables.Something like (assuming the legacy tables are in the same database): If legacy_table has columns foo and bar foo bar --- --- 1 one 2 two ActiveRecord::Base.connection.select_all("SELECT * FROM legacy_table") returns an array of hashes: [{''foo''=>''1'', ''bar''=>''one''}, {''foo''=>''2'', ''bar''=>''two''}] -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 can torture your query to the point where it will return records that mimic the model table, you could pass that into YourModel.find_by_sql. That may be convenient... -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Rob Biedenharn Sent: Wednesday, July 09, 2008 7:56 AM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: Access Data Outside of Active Record On Jul 9, 2008, at 10:23 AM, Jobu wrote:> On Jul 9, 5:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Jul 8, 11:38 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> I''d like to write a data import script as a rake task. It would >>> execute a moderately complex query against some legacy tables >>> returning a recordset. I''d like to get the results of that >>> recordset into the rake task and iterate over it creating instances >>> of ActiveRecord derived models. >> >> Seems reasonable enough, but what''s the question you''re asking ? >> > > I''d like to know how to do the first part. How do I execute a non- > CRUD query against the legacy tables and receive a recordset of those > results? There''s currently no ActiveRecord derived model in place for> the legacy tables.Something like (assuming the legacy tables are in the same database): If legacy_table has columns foo and bar foo bar --- --- 1 one 2 two ActiveRecord::Base.connection.select_all("SELECT * FROM legacy_table") returns an array of hashes: [{''foo''=>''1'', ''bar''=>''one''}, {''foo''=>''2'', ''bar''=>''two''}] -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 Jul 9, 10:41 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9 Jul 2008, at 15:23, Jobu wrote: > > > > > > > On Jul 9, 5:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On Jul 8, 11:38 pm, Jobu <rosens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> I''d like to write a data import script as a rake task. It would > >>> execute a moderately complex query against some legacy tables > >>> returning a recordset. I''d like to get the results of that > >>> recordset > >>> into the rake task and iterate over it creating instances of > >>> ActiveRecord derived models. > > >> Seems reasonable enough, but what''s the question you''re asking ? > > > I''d like to know how to do the first part. How do I execute a non- > > CRUD query against the legacy tables and receive a recordset of those > > results? There''s currently no ActiveRecord derived model in place for > > the legacy tables. > > Have you played with ActiveRecord::Base.connection.select_all ? >Nope, that''s what I needed. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---