Skip to content

Instantly share code, notes, and snippets.

@jdgarrido
Last active July 20, 2016 14:24
Show Gist options
  • Save jdgarrido/6fb9768fc2c21a0f31ff93afcf2c1fe2 to your computer and use it in GitHub Desktop.
Save jdgarrido/6fb9768fc2c21a0f31ff93afcf2c1fe2 to your computer and use it in GitHub Desktop.
modelo papu
class Comuna < ActiveRecord::Base
belongs_to :provincia
has_many :sede
def to_s
self.nombre
end
end
class AddComunaToSede < ActiveRecord::Migration
def change
add_reference :sedes, :comuna, index: true, foreign_key: true
end
end
class Provincia < ActiveRecord::Base
belongs_to :region
has_many :comunas
end
class Region < ActiveRecord::Base
has_paper_trail
has_and_belongs_to_many :partidos
has_many :provincias
has_many :comunas, through: :provincias
has_many :distritos
has_many :circunscripcions
def to_s
self.nombre
end
end
class Sede < ActiveRecord::Base
has_paper_trail
belongs_to :partido
belongs_to :region
belongs_to :comuna
validates_presence_of :direccion, :region_id, :comuna_id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment