質問するログイン新規登録

回答編集履歴

1

追記

2021/10/01 12:55

投稿

winterboum
winterboum

スコア23669

answer CHANGED
@@ -6,4 +6,15 @@
6
6
  です。
7
7
  a2 の composer_songs を test1, test2 に置き換えるなら
8
8
  `a2.composer_songs = [test1, test2]`
9
- です。
9
+ です。
10
+
11
+ ### 追記
12
+ 関連定義に違和感があるのです
13
+ 例えば `has_many :composer_song_songs`
14
+ これは CompoerSongSong というmodelをhas_manyしてるというもの。
15
+
16
+ ある Song を ComposerSong として Artistに関連付けるなら
17
+ 中間tableは Artist と ComposerSong をつなぐものとして、 ArtistComposerSong で、
18
+ `class Artist
19
+ has_many :composer_songs, class_name: "Song", through: :artist_composer_songs`
20
+ とするのがよいのでは。