LoginSignup
0
0

More than 5 years have passed since last update.

中間テーブルとのアソシエーションでエラーが出る。

Posted at

エラー内容

has_many throughでなんとかなんとかって出てくる。

image.png

エラー元のソースコード

group.rb
class Group < ApplicationRecord
  has_many :users, through: :group_users
  has_many :group_users
end

原因と考えられるもの

エラー文からgroup_usersが中間テーブルのアソシエーションの後に来てることが原因だと考えた。

解決コード

group.rb
class Group < ApplicationRecord
#group_usersのコードをthroughの前に持ってくる。
  has_many :group_users
  has_many :users, through: :group_users
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0