Jobu | 9 Jul 00:36

Access Data Outside of Active Record


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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Frederick Cheung | 9 Jul 11:31

Re: Access Data Outside of Active Record


On Jul 8, 11:38 pm, Jobu <rosens...@...> 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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Jobu | 9 Jul 16:23

Re: Access Data Outside of Active Record


On Jul 9, 5:31 am, Frederick Cheung <frederick.che...@...>
wrote:
> On Jul 8, 11:38 pm, Jobu <rosens...@...> 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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Frederick Cheung | 9 Jul 16:41

Re: Access Data Outside of Active Record


On 9 Jul 2008, at 15:23, Jobu wrote:

>
> On Jul 9, 5:31 am, Frederick Cheung <frederick.che...@...>
> wrote:
>> On Jul 8, 11:38 pm, Jobu <rosens...@...> 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.
(Continue reading)

Jobu | 10 Jul 00:23

Re: Access Data Outside of Active Record


On Jul 9, 10:41 am, Frederick Cheung <frederick.che...@...>
wrote:
> On 9 Jul 2008, at 15:23, Jobu wrote:
>
>
>
>
>
> > On Jul 9, 5:31 am, Frederick Cheung <frederick.che...@...>
> > wrote:
> >> On Jul 8, 11:38 pm, Jobu <rosens...@...> 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 ?
>

(Continue reading)

Rob Biedenharn | 9 Jul 16:55

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...@...>
> wrote:
>> On Jul 8, 11:38 pm, Jobu <rosens...@...> 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

(Continue reading)

Pardee, Roy | 9 Jul 17:28

Re: Access Data Outside of Active Record


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@...
[mailto:rubyonrails-talk@...] On Behalf Of Rob Biedenharn
Sent: Wednesday, July 09, 2008 7:56 AM
To: rubyonrails-talk@...
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...@...>
> wrote:
>> On Jul 8, 11:38 pm, Jobu <rosens...@...> 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

(Continue reading)


Gmane