Loading flat-file data into multiple tables

I have a CSV export file with 11 columns that I need to ‘split’ into
three related tables (some columns go into each table).

Departments (have many projects)
Projects (have many audiences)
Audiences (have many projects)

I understand the model relationships, and have those built.

I am using FasterCSV for file importing and have that iterating
through the CSV rows using a block.

So now I need to 1) understand how to assign the array values to model
objects inside the block; and 2) make sure that the data loaded stays
synchronized. That is, when the 11 columns of the flat file split into
three tables, they need to keep their relations. This seems to require
a multi-table transaction. I am assuming that the foreign keys will
hold it all together.

Am I on the right track here? Can someone provide an example of a
nested transaction that would get me a little further down this path?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs