Fix HasManyThroughOrderErrors

This commit is contained in:
Henne Vogelsang 2022-02-11 16:49:42 +01:00
parent e15fedd9b0
commit 5c5374252c
No known key found for this signature in database
GPG key ID: 97DDB66BDAF8D4D6
2 changed files with 9 additions and 7 deletions

View file

@ -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

View file

@ -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