krusty.ar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-30  21:08 UTC
Problem with data migration and acts_as_tree
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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- funciones (findInterval, which) y simulación discreta
- Acumulado hasta una fecha exacta según individuo
- Frecuencia absoluta acumulada por individuo y por
- Frecuencia absoluta acumulada por individuo y por año
- ALQUILER PARA GRUPO HOTELERO o INVERSORES RENTISTAS
