Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions app/models/regular_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RegularEvent < ApplicationRecord # rubocop:disable Metrics/ClassLength

scope :holding, -> { where(finished: false) }
scope :participated_by, ->(user) { where(id: all.filter { |e| e.participated_by?(user) }.map(&:id)) }
scope :organizer_event, ->(user) { joins(:organizers).where(organizers: { user_id: user.id }) }
scope :organizer_event, ->(user) { joins(:regular_event_organizers).where(regular_event_organizers: { user: user }) }
scope :scheduled_on, ->(date) { holding.filter { |event| event.scheduled_on?(date) } }
scope :scheduled_on_without_ended, ->(date) { holding.filter { |event| event.scheduled_on?(date) && !event.ended?(date) } }

Expand All @@ -69,10 +69,8 @@ class RegularEvent < ApplicationRecord # rubocop:disable Metrics/ClassLength
}

belongs_to :user
has_many :organizers, dependent: :destroy
# TODO: テーブル名を変更したら修正する
has_many :regular_event_organizers, class_name: 'Organizer', dependent: :destroy
has_many :users, through: :organizers
has_many :regular_event_organizers, dependent: :destroy
has_many :users, through: :regular_event_organizers
has_many :regular_event_repeat_rules, dependent: :destroy
accepts_nested_attributes_for :regular_event_repeat_rules, allow_destroy: true
has_many :regular_event_participations, dependent: :destroy
Expand All @@ -88,7 +86,7 @@ def self.ransackable_attributes(_auth_object = nil)
end

def self.ransackable_associations(_auth_object = nil)
%w[user organizers users regular_event_repeat_rules participants comments reactions watches]
%w[user regular_event_organizers users regular_event_repeat_rules participants comments reactions watches]
end

def scheduled_on?(date)
Expand All @@ -108,7 +106,7 @@ def next_event_date
end

def organizers
users.preload(avatar_attachment: :blob).order('organizers.created_at')
users.preload(avatar_attachment: :blob).order('regular_event_organizers.created_at')
end

def cancel_participation(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Organizer < ApplicationRecord
class RegularEventOrganizer < ApplicationRecord
belongs_to :user
belongs_to :regular_event

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class User < ApplicationRecord # rubocop:todo Metrics/ClassLength
has_many :articles, dependent: :destroy
has_many :bookmarks, dependent: :destroy
has_many :regular_events, dependent: :destroy
has_many :organizers, dependent: :destroy
has_many :regular_event_organizers, dependent: :destroy
has_many :hibernations, dependent: :destroy
has_many :authored_books, dependent: :destroy
accepts_nested_attributes_for :authored_books, allow_destroy: true
Expand Down Expand Up @@ -192,7 +192,7 @@ class User < ApplicationRecord # rubocop:todo Metrics/ClassLength
source: :follower

has_many :organize_regular_events,
through: :organizers,
through: :regular_event_organizers,
source: :regular_event

has_many :participate_regular_events,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeOrganizersToRegularEventOrganizer < ActiveRecord::Migration[8.1]
def change
rename_table :organizers, :regular_event_organizers
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveIndexUserIdFromRegularEventOrganizers < ActiveRecord::Migration[8.1]
def change
remove_index :regular_event_organizers, :user_id, name: "index_regular_event_organizers_on_user_id"
end
Comment on lines +2 to +4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LGTM]
不要なインデックスの削除、よい〜

Copy link
Copy Markdown
Contributor Author

@yokomaru yokomaru Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たださん、ご確認いただきありがとうございましたーー!🙌

end
25 changes: 12 additions & 13 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_04_15_000001) do
ActiveRecord::Schema[8.1].define(version: 2026_04_15_062046) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -527,16 +527,6 @@
t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true
end

create_table "organizers", force: :cascade do |t|
t.datetime "created_at", null: false
t.bigint "regular_event_id", null: false
t.datetime "updated_at", null: false
t.bigint "user_id", null: false
t.index ["regular_event_id"], name: "index_organizers_on_regular_event_id"
t.index ["user_id", "regular_event_id"], name: "index_organizers_on_user_id_and_regular_event_id", unique: true
t.index ["user_id"], name: "index_organizers_on_user_id"
end

create_table "pages", id: :serial, force: :cascade do |t|
t.text "body", null: false
t.datetime "created_at", precision: nil, null: false
Expand Down Expand Up @@ -697,6 +687,15 @@
t.index ["user_id"], name: "index_reactions_on_user_id"
end

create_table "regular_event_organizers", force: :cascade do |t|
t.datetime "created_at", null: false
t.bigint "regular_event_id", null: false
t.datetime "updated_at", null: false
t.bigint "user_id", null: false
t.index ["regular_event_id"], name: "index_regular_event_organizers_on_regular_event_id"
t.index ["user_id", "regular_event_id"], name: "index_regular_event_organizers_on_user_id_and_regular_event_id", unique: true
end

create_table "regular_event_participations", force: :cascade do |t|
t.datetime "created_at", null: false
t.bigint "regular_event_id", null: false
Expand Down Expand Up @@ -1144,8 +1143,6 @@
add_foreign_key "oauth_access_grants", "users", column: "resource_owner_id"
add_foreign_key "oauth_access_tokens", "oauth_applications", column: "application_id"
add_foreign_key "oauth_access_tokens", "users", column: "resource_owner_id"
add_foreign_key "organizers", "regular_events"
add_foreign_key "organizers", "users"
add_foreign_key "pages", "practices"
add_foreign_key "pages", "users"
add_foreign_key "pair_work_schedules", "pair_works"
Expand All @@ -1165,6 +1162,8 @@
add_foreign_key "radio_button_choices", "radio_buttons"
add_foreign_key "radio_buttons", "survey_questions"
add_foreign_key "reactions", "users"
add_foreign_key "regular_event_organizers", "regular_events"
add_foreign_key "regular_event_organizers", "users"
add_foreign_key "regular_event_participations", "regular_events"
add_foreign_key "regular_event_participations", "users"
add_foreign_key "regular_event_repeat_rules", "regular_events"
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
regular_events
regular_event_repeat_rules
regular_event_participations
organizers
regular_event_organizers
hibernations
footprints
authored_books
Expand Down
Loading