diff --git a/app/models/conference.rb b/app/models/conference.rb index 8d0b786d..cac3a849 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -28,8 +28,8 @@ class Conference < ApplicationRecord delegate :city, :country_name, to: :venue, allow_nil: true delegate :name, :street, to: :venue, prefix: true, allow_nil: true - has_many :physical_tickets, through: :ticket_purchases has_many :ticket_purchases, dependent: :destroy + has_many :physical_tickets, through: :ticket_purchases has_many :payments, dependent: :destroy has_many :supporters, through: :ticket_purchases, source: :user has_many :tickets, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 7c764fa1..c7e45732 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +7,6 @@ class UserDisabled < StandardError end class User < ApplicationRecord - rolify # prevent N+1 queries with has_cached_role? by preloading roles *always* default_scope { preload(:roles) } @@ -17,8 +16,15 @@ class User < ApplicationRecord where('ticket_purchases.conference_id = ?', conference) end end + has_many :tickets, through: :ticket_purchases, source: :ticket do + def for_registration conference + where(conference: conference, registration_ticket: true).first + end + end + has_many :users_roles has_many :roles, through: :users_roles, dependent: :destroy + rolify has_paper_trail on: [:create, :update], ignore: [:sign_in_count, :remember_created_at, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip, :unconfirmed_email, :avatar_content_type, :avatar_file_size, :avatar_updated_at, :updated_at, :confirmation_sent_at, :confirmation_token, :reset_password_token] @@ -69,11 +75,7 @@ class User < ApplicationRecord end has_many :events_registrations, through: :registrations has_many :payments, dependent: :destroy - has_many :tickets, through: :ticket_purchases, source: :ticket do - def for_registration conference - where(conference: conference, registration_ticket: true).first - end - end + has_many :votes, dependent: :destroy has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy