# Problem with data migration and acts\_as\_tree

**URL:** <https://www.ruby-forum.com/t/problem-with-data-migration-and-acts-as-tree/113421>\
**Category:** Rails\
**Created:** [August 30, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/problem-with-data-migration-and-acts-as-tree/113421 "2007-08-30T23:08:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 30, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/problem-with-data-migration-and-acts-as-tree/113421/1 "2007-08-30T23:08:54Z")

</div>

Hi, this is my first post here, my name is Lucas and I’m just starting  
with rails.

For one of the first models I made (an accounts plan), I had some  
example data in a CSV file, so I created this migration, the idea is  
to detect the parent/child relationships according to the account  
number, the code works right (if I insert some puts here and there, I  
can see it), but when the migration finishes, the parent\_id column in  
the table is empty.

What am I missing?

Thanks

The migration:

class PlanDeCuentas \< ActiveRecord::Migration  
def self.up  
down  
File.open(‘Plan.csv’, ‘r’) do |f|  
f.map {|l| l.chomp}.each do |linea|  
cuenta,nombre = linea.split(’,’)  
Cuenta.create(:cuenta =\> cuenta, :nombre =\>  
nombre , :imputable =\> true)  
end  
end  
Cuenta.find(:all).each do |c|  
c.children \<\< Cuenta.find(:all, :conditions =\> [“cuenta like ?  
and cuenta \<\> ?”, c.cuenta+’%’,c.cuenta])  
c.imputable = false if c.children.size \> 0  
c.save!  
end  
end

def self.down  
Cuenta.delete\_all  
end  
end

The model is this:

class Cuenta \< ActiveRecord::Base  
acts\_as\_tree :order =\> “cuenta”  
end

And the file looks like this:

1,ACTIVO  
11,ACTIVO CORRIENTE  
1101,DISPONIBILIDADES  
110101,CAJA  
11010101,CAJA  
11010102,FONDO FIJO  
11010103,RECAUDACIONES A DEPOSITAR  
110102,BANCOS  
11010201,GALICIA CTA CTE  
11010202,HSBC CTA CTE  
11010203,PATAGONIA CTA CTE  
12,ACTIVO NO CORRIENTE  
1201,BIENES DE USO  
120101,MUEBLES Y â”ŒTILES  
12010101,MUEBLES Y â”ŒTILES  
12010102,AMORT. ACUMULADA M. Y â”ŒTILES  
120102,EQUIPOS Y SISTEMAS  
12010201,EQUIPOS Y SISTEMAS  
12010202,AMORT. ACUMULADA EQUIPOS Y SISTEMAS  
120103,INSTALACIONES  
12010301,INSTALACIONES  
12010302,AMORT. ACUMULADA INSTALACIONES  
2,PASIVO  
21,PASIVO CORRIENTE  
2101,DEUDAS COMERCIALES  
210101,PROVEEDORES
