From 7473e889ee9cab4f5b909589fd3e8e96124983c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Sat, 4 May 2019 21:03:08 +0200 Subject: [PATCH] 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. --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index bc71f61f..ec3132e1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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