Skip to content
Snippets Groups Projects
Commit 2caf3d32 authored by Teal's avatar Teal
Browse files

add relevant stages relation

parent ba6ed272
Branches
No related tags found
No related merge requests found
......@@ -8,6 +8,9 @@ class Conference < ApplicationRecord
validates :time_zone, presence: true, inclusion: { in: ActiveSupport::TimeZone.all.map(&:name) }
has_many :relevant_stage_links, class_name: 'RelevantStage'
has_many :relevant_stages, through: :relevant_stage_links, source: :stage
def days
(starts_at.to_date..ends_at.to_date)
end
......
class RelevantStage < ApplicationRecord
belongs_to :conference
belongs_to :stage
validates :conference_id, uniqueness: { scope: :stage_id }
end
......@@ -3,4 +3,7 @@ class Stage < ApplicationRecord
has_many :sessions
validates :ref_id, uniqueness: { scope: :conference_id }
has_many :relevant_stage_links, class_name: 'RelevantStage'
has_many :relevant_conferences, through: :relevant_stage_links, source: :conference
end
class CreateRelevantStages < ActiveRecord::Migration[7.1]
def change
create_table :relevant_stages do |t|
t.references :conference, null: false, foreign_key: true
t.references :stage, null: false, foreign_key: true
t.timestamps
end
add_index :relevant_stages, [:conference_id, :stage_id], unique: true
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_05_26_165259) do
ActiveRecord::Schema[7.1].define(version: 2024_05_27_191332) do
create_table "assignments", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "session_id", null: false
......@@ -72,6 +72,16 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_26_165259) do
t.datetime "updated_at", null: false
end
create_table "relevant_stages", force: :cascade do |t|
t.integer "conference_id", null: false
t.integer "stage_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["conference_id", "stage_id"], name: "index_relevant_stages_on_conference_id_and_stage_id", unique: true
t.index ["conference_id"], name: "index_relevant_stages_on_conference_id"
t.index ["stage_id"], name: "index_relevant_stages_on_stage_id"
end
create_table "revision_sets", force: :cascade do |t|
t.integer "conference_id", null: false
t.datetime "created_at", null: false
......@@ -260,6 +270,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_26_165259) do
add_foreign_key "assignments", "sessions"
add_foreign_key "assignments", "users"
add_foreign_key "relevant_stages", "conferences"
add_foreign_key "relevant_stages", "stages"
add_foreign_key "revision_sets", "conferences"
add_foreign_key "revisions", "conferences"
add_foreign_key "session_speakers", "sessions"
......
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
conference: one
stage: one
two:
conference: two
stage: two
require "test_helper"
class RelevantStageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment