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

質問編集履歴

2

njk

2020/09/25 11:35

投稿

Meitoku
Meitoku

スコア44

title CHANGED
File without changes
body CHANGED
@@ -17,26 +17,30 @@
17
17
  ###関係
18
18
 
19
19
  **tweetテーブル**
20
- |id|text|school.id|
20
+ |id|text|school_a.id|school_b.id
21
21
  |:--|:--:|--:|
22
- |1|おはよう|1|
22
+ |1|おはよう|1|2|
23
23
 
24
- school.idはA高校を指しています
24
+ school_a.idはA高校を指しています
25
+ school_b.idはB高校を指しています
25
26
 
26
27
  **categoriesテーブル**
27
28
  |id|name|
28
29
  |:--|:--:|
29
30
  |1|A高校|
31
+ |2|B高校|
30
32
 
31
33
  **Tweetモデル**
32
34
 
33
35
  ```
34
- belongs_to :school,class_name: 'Category', foreign_key: 'school_id'
36
+ belongs_to :school_a,class_name: 'Category', foreign_key: 'school_a_id'
37
+ belongs_to :school_b,class_name: 'Category', foreign_key: 'school_b_id'
35
38
  ```
36
39
 
37
40
  **Categoryモデル**
38
41
 
39
42
  ```
40
43
  has_many :tweets
41
- has_many :school_tweets,class_name: 'Tweet', foreign_key: 'school_id'
44
+ has_many :school_a_tweets,class_name: 'Tweet', foreign_key: 'school_a_id'
45
+ has_many :school_b_tweets,class_name: 'Tweet', foreign_key: 'school_b_id'
42
46
  ```

1

i

2020/09/25 11:35

投稿

Meitoku
Meitoku

スコア44

title CHANGED
File without changes
body CHANGED
@@ -37,5 +37,6 @@
37
37
  **Categoryモデル**
38
38
 
39
39
  ```
40
+ has_many :tweets
40
41
  has_many :school_tweets,class_name: 'Tweet', foreign_key: 'school_id'
41
42
  ```