Skip to content

Instantly share code, notes, and snippets.

@benburkert
Created September 24, 2008 20:31

Revisions

  1. benburkert revised this gist Sep 24, 2008. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -28,13 +28,13 @@ class Banco
    property :direccion, String, :length => 150
    property :contacto, String, :length => 100
    property :aba, String, :length => 40
    property :pais_id, Integer, :nullable => false

    # Configuración de las asociaciones
    has n, :cuenta_bancarias
    belongs_to :pais
    belongs_to :pais, :child_key => [:pais_id]

    # Propiedades para las asociaciones
    property :pais_id, Integer, :nullable => false

    # Propiedades comunes de marca de tiempo
    # created_at, updated_at, deleted_at
  2. @lobo-tuerto lobo-tuerto created this gist Sep 24, 2008.
    62 changes: 62 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    class Pais
    include DataMapper::Resource

    # Configuración de las relaciones
    has n, :bancos

    # Propiedades principales
    property :id, Serial
    property :nombre, String, :length => (1..50), :nullable => false
    property :nombre_corto, String, :length => (1..20), :nullable => false

    # Propiedades especiales
    # Propiedades comunes de marca de tiempo
    # created_at, updated_at, deleted_at
    tiene_marcas_de_tiempo
    end


    class Banco
    include DataMapper::Resource

    # Propiedades principales
    property :id, Serial
    property :nombre, String, :length => (1..100), :nullable => false
    property :nombre_corto, String, :length => (1..30), :nullable => false
    property :sucursal, String, :length => 50
    property :telefono, String, :length => 30
    property :direccion, String, :length => 150
    property :contacto, String, :length => 100
    property :aba, String, :length => 40

    # Configuración de las asociaciones
    has n, :cuenta_bancarias
    belongs_to :pais

    # Propiedades para las asociaciones
    property :pais_id, Integer, :nullable => false

    # Propiedades comunes de marca de tiempo
    # created_at, updated_at, deleted_at
    tiene_marcas_de_tiempo

    #TODO: Hacer un plugin con metaprogramming que haga esto donde sea incluido
    before :save, :checa_pais
    def checa_pais
    # Eliminamos cualquier error previo (limpia los anteriores antes de darle una pasada)
    a_checar = :pais
    self.errors[a_checar] = []

    if(pais_id.nil?)
    self.errors.add(a_checar, "No se especificó un país.")
    throw :halt
    end

    temporal = Pais.get(pais_id)

    if(temporal.nil?)
    self.errors.add(a_checar, "Ese país no existe.")
    throw :halt
    end
    end
    end