Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Last active November 13, 2017 20:19
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 ornerymoose/2ea11de29867684a5c86ca5031c94004 to your computer and use it in GitHub Desktop.
Save ornerymoose/2ea11de29867684a5c86ca5031c94004 to your computer and use it in GitHub Desktop.
class Child < ApplicationRecord
has_one :outage, through: :relationship
has_one :relationship
end
class Outage < ApplicationRecord
has_many :outages, through: :relationships
end
class Relationship < ApplicationRecord
belongs_to :outage
belongs_to :child
validates_uniqueness_of :child_id, :scope => :outage_id
end
ActiveRecord::Schema.define(version: 20171113194934) do
create_table "children", force: :cascade do |t|
t.string "otn"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "outages", force: :cascade do |t|
t.string "htn"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "relationships", force: :cascade do |t|
t.integer "outage_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "child_id"
t.index ["child_id"], name: "index_relationships_on_child_id"
t.index ["outage_id"], name: "index_relationships_on_outage_id"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment