Skip to content

Instantly share code, notes, and snippets.

@shushugah
Created September 16, 2014 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shushugah/7619a473fcfd9992fdab to your computer and use it in GitHub Desktop.
Save shushugah/7619a473fcfd9992fdab to your computer and use it in GitHub Desktop.
#2 models
class EarlyVoteSite < ActiveRecord::Base
has_and_belongs_to_many :locality,
:foreign_key => 'locality_id', :primary_key => 'p_id'
end
class Locality < ActiveRecord::Base
has_and_belongs_to_many :early_vote_sites,
:foreign_key => 'early_vote_site_id', :primary_key => 'p_id'
end
#Goal: EarlyVoteSite.find(n).localities
unable to at moment, currently doing Locality.find_by(p_id: EarlyVoteSite.find(n).locality_id)
#######schema############
ActiveRecord::Schema.define(version: 20140915192200) do
create_table "early_vote_sites", force: true do |t|
t.string "name"
t.string "address_line1"
t.string "address_line2"
t.string "address_city"
t.string "address_state"
t.string "address_zip"
t.string "directions"
t.string "start_date"
t.string "end_date"
t.string "days_times_open"
t.integer "locality_id"
t.integer "p_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "localities", force: true do |t|
t.string "name"
t.string "state_id"
t.string "county_type"
t.string "election_administration_id"
t.integer "p_id"
t.integer "early_vote_site_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment