0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

アソシエーションの順番あり

Posted at

Aテーブル
Bテーブル
C中間テーブルを作りました

Aテーブル
class A < ApplicationRecord
  has_many :Cテーブル
  has_many :Bテーブル, through: :Cテーブル
  
  validates :name, uniqueness: true
end
```

````rb:Bテーブル
class B < ApplicationRecord
  has_many :Aテーブル, through: :Cテーブル
  has_many :Cテーブル
end
```

Bのテーブルで問題発生しています
![20210523-212324.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/960935/815fb5a4-04b9-b810-06de-0581f35fbc56.png)


雰囲気の訳)先にCテーブルとのアソシエーションを書いて、次に中間テーブルを設定しないと順番が変なのでCテーブルを通してAテーブルとなんていう記述はできませんといっています。

````rb:(修正)Bテーブル
class B < ApplicationRecord
  has_many :Cテーブル
  has_many :Aテーブル, through: :Cテーブル

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?