Define ticket_purchases before through association

In the User model, a has_many :through association
'User#physical_tickets' which goes through 'User#ticket_purchases' was
defined before the through association was defined. This doesn't work in
Rails 5.1.
This commit is contained in:
Ana María Martínez Gómez 2019-05-04 21:03:08 +02:00
parent 41d6fad7a5
commit 7473e889ee
No known key found for this signature in database
GPG key ID: EACB9B4BC80C0347

View file

@ -11,6 +11,7 @@ class User < ApplicationRecord
# prevent N+1 queries with has_cached_role? by preloading roles *always*
default_scope { preload(:roles) }
has_many :ticket_purchases, dependent: :destroy
has_many :physical_tickets, through: :ticket_purchases do
def by_conference(conference)
where('ticket_purchases.conference_id = ?', conference)
@ -67,7 +68,6 @@ class User < ApplicationRecord
end
end
has_many :events_registrations, through: :registrations
has_many :ticket_purchases, dependent: :destroy
has_many :payments, dependent: :destroy
has_many :tickets, through: :ticket_purchases, source: :ticket do
def for_registration conference