# CSV Import with Nested Set problem

**URL:** <https://www.ruby-forum.com/t/csv-import-with-nested-set-problem/157488>\
**Category:** Rails\
**Created:** [January 12, 2009, 8:23am UTC](https://www.ruby-forum.com/t/csv-import-with-nested-set-problem/157488 "2009-01-12T08:23:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rnewbee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3be4f8/32.png) [@rnewbee](https://www.ruby-forum.com/u/rnewbee)\
**Post date:** [January 12, 2009, 8:23am UTC](https://www.ruby-forum.com/t/csv-import-with-nested-set-problem/157488/1 "2009-01-12T08:23:33Z")

</div>

Hi all,

Am struggling to get this to work:

I am importing CSV file into the database.

This is my code

def import

```
  file = params[:import][:file]
  row_count=0

    FasterCSV.parse(file, :headers => true) do |food|

      import_this_row = {:id => food[0],
                 :recipe_name => food[1],
                 :recipe_id=> food[2],
                 :reference => food[3],

           }

          @recipes = Recipe.new(import_this_row)

  @recipe.save!
             end

```

end

The problem comes with recipe\_id where I am using awesome\_nested\_type  
and in the csv file I have this under the recipe\_id rows:  
Food|Beverages|Pineapple Shake  
Food|Snacks|Burger

Now when I import I need to get the id of the recipe\_id after reading  
the name mentioned in the row.

Could anyone please guide me with this…

Cheers

Sam
