Обновление приложения с Rails 4.2.9 до Rails 5.2.1.
Через большую часть неприятной части обновления зависимостей и прочего, и, наконец, приложение, работающее на console
, теперь пытается попасть на страницы на server
. Некоторые страницы загружаются, а другие:
Cannot have a has_many :through association 'User#clubs' which goes through 'User#memberships' before the through association is defined.
Непонятно, что могло быть изменено в Rails 5, чтобы вызвать это? Даже не знаю, с чего начать.
Мысли?
Кажется, сбой в строке, указанной ниже:
class ViewableStories
...
def for_user
Story
.includes(:publications)
.references(:publications)
.where(
stories[:user_id]
.eq(@user.id)
.or(
publications[:club_id]
.in(@user.club_ids) <<==== execution halts
.and(
publications[:publish_on]
.lt(Date.today)
.or(publications[:publish_on].eq(nil))
)
)
)
end
end
Которая называется от model/story.rb
def self.viewable_published_stories_for(user)
ViewableStories
.for_user(user)
.includes(:cover_image, :user, :table_of_contents)
.published
.chronological
end
Вероятно, это просто проблема с заказом вашей модели. has_many
должен предшествовать has_many through
.
Итак, прямо сейчас у вас, вероятно, есть:
class User < ApplicationRecord
...
has_many :clubs, through: :memberships
has_many :memberships
...
end
Вам просто нужно переместить has_many :memberships
над has_many through
:
class User < ApplicationRecord
...
has_many :memberships
has_many :clubs, through: :memberships
...
end
Ага. это было так просто! Спасибо! Но в Rails 4.x этого не было. Кажется, не могу найти, где это изменение задокументировано. Если кто знает, напишите, пожалуйста. Хотел бы знать, что я упустил из виду. Спасибо еще раз!