From c9ae859bcf2525b3923b33f55bb0735defea2601 Mon Sep 17 00:00:00 2001 From: Rishabh Singh Date: Sat, 17 Aug 2019 18:10:27 +0530 Subject: [PATCH] Set up association and models --- app/models/booth.rb | 1 + app/models/booth_type.rb | 17 +++++++++++++++++ app/models/conference.rb | 1 + app/models/program.rb | 1 + db/schema.rb | 13 ++++++++++++- 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/models/booth_type.rb diff --git a/app/models/booth.rb b/app/models/booth.rb index 71ab6e98..994b0aee 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -7,6 +7,7 @@ class Booth < ApplicationRecord attr_accessor :invite_responsible belongs_to :conference + belongs_to :booth_type has_many :booth_requests, dependent: :destroy has_many :users, through: :booth_requests diff --git a/app/models/booth_type.rb b/app/models/booth_type.rb new file mode 100644 index 00000000..bc5909ac --- /dev/null +++ b/app/models/booth_type.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class BoothType < ApplicationRecord + belongs_to :program, touch: true + has_many :booths, dependent: :restrict_with_error + + has_paper_trail meta: { conference_id: :conference_id }, + ignore: %i[updated_at] + + validates :title, presence: true + + private + + def conference_id + program.conference_id + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index be3c36ad..914fc27d 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -52,6 +52,7 @@ class Conference < ApplicationRecord through: :program, source: :events has_many :event_types, through: :program + has_many :booth_types, through: :program has_many :surveys, as: :surveyable, dependent: :destroy do def for_registration diff --git a/app/models/program.rb b/app/models/program.rb index 8db24c6c..d13c8413 100644 --- a/app/models/program.rb +++ b/app/models/program.rb @@ -9,6 +9,7 @@ class Program < ApplicationRecord has_many :cfps, dependent: :destroy has_many :event_types, dependent: :destroy + has_many :booth_types, dependent: :destroy has_many :tracks, dependent: :destroy has_many :difficulty_levels, dependent: :destroy has_many :schedules, dependent: :destroy diff --git a/db/schema.rb b/db/schema.rb index b199367e..fa05b8fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_03_143107) do +ActiveRecord::Schema.define(version: 2019_08_17_094930) do create_table "answers", force: :cascade do |t| t.string "title" @@ -28,6 +28,15 @@ ActiveRecord::Schema.define(version: 2019_06_03_143107) do t.index ["user_id"], name: "index_booth_requests_on_user_id" end + create_table "booth_types", force: :cascade do |t| + t.integer "program_id" + t.string "title", null: false + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["program_id"], name: "index_booth_types_on_program_id" + end + create_table "booths", force: :cascade do |t| t.string "title" t.text "description" @@ -39,6 +48,8 @@ ActiveRecord::Schema.define(version: 2019_06_03_143107) do t.integer "conference_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "booth_type_id" + t.index ["booth_type_id"], name: "index_booths_on_booth_type_id" end create_table "cfps", force: :cascade do |t|