diff --git a/app/models/event.rb b/app/models/event.rb index 82f8204b..14d82e77 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -34,9 +34,12 @@ class Event < ApplicationRecord belongs_to :difficulty_level belongs_to :program + has_and_belongs_to_many :favourite_users, class_name: 'User' + accepts_nested_attributes_for :event_users, allow_destroy: true accepts_nested_attributes_for :speakers, allow_destroy: true accepts_nested_attributes_for :users + accepts_nested_attributes_for :favourite_users before_create :generate_guid diff --git a/app/models/user.rb b/app/models/user.rb index 4cbac281..1bb43315 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -86,6 +86,8 @@ class User < ApplicationRecord has_many :booths, through: :booth_requests has_many :survey_replies has_many :survey_submissions + has_and_belongs_to_many :favourite_events, class_name: 'Event' + accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } diff --git a/db/migrate/20160811143427_create_events_users.rb b/db/migrate/20160811143427_create_events_users.rb new file mode 100644 index 00000000..64a7fa6e --- /dev/null +++ b/db/migrate/20160811143427_create_events_users.rb @@ -0,0 +1,8 @@ +class CreateEventsUsers < ActiveRecord::Migration + def change + create_table :events_users, id: false do |t| + t.references :event + t.references :user + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 298e77a3..22184144 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -263,6 +263,11 @@ ActiveRecord::Schema[7.0].define(version: 2024_11_21_114727) do t.datetime "created_at" end + create_table "events_users", id: false, force: :cascade do |t| + t.integer "event_id" + t.integer "user_id" + end + create_table "lodgings", force: :cascade do |t| t.string "name" t.text "description"