質問編集履歴

2

njk

2020/09/25 11:35

投稿

Meitoku
Meitoku

スコア44

test CHANGED
File without changes
test CHANGED
@@ -36,15 +36,17 @@
36
36
 
37
37
  **tweetテーブル**
38
38
 
39
- |id|text|school.id|
39
+ |id|text|school_a.id|school_b.id
40
40
 
41
41
  |:--|:--:|--:|
42
42
 
43
- |1|おはよう|1|
43
+ |1|おはよう|1|2|
44
44
 
45
45
 
46
46
 
47
- school.idはA高校を指しています
47
+ school_a.idはA高校を指しています
48
+
49
+ school_b.idはB高校を指しています
48
50
 
49
51
 
50
52
 
@@ -56,6 +58,8 @@
56
58
 
57
59
  |1|A高校|
58
60
 
61
+ |2|B高校|
62
+
59
63
 
60
64
 
61
65
  **Tweetモデル**
@@ -64,7 +68,9 @@
64
68
 
65
69
  ```
66
70
 
67
- belongs_to :school,class_name: 'Category', foreign_key: 'school_id'
71
+ belongs_to :school_a,class_name: 'Category', foreign_key: 'school_a_id'
72
+
73
+ belongs_to :school_b,class_name: 'Category', foreign_key: 'school_b_id'
68
74
 
69
75
  ```
70
76
 
@@ -78,6 +84,8 @@
78
84
 
79
85
  has_many :tweets
80
86
 
81
- has_many :school_tweets,class_name: 'Tweet', foreign_key: 'school_id'
87
+ has_many :school_a_tweets,class_name: 'Tweet', foreign_key: 'school_a_id'
88
+
89
+ has_many :school_b_tweets,class_name: 'Tweet', foreign_key: 'school_b_id'
82
90
 
83
91
  ```

1

i

2020/09/25 11:35

投稿

Meitoku
Meitoku

スコア44

test CHANGED
File without changes
test CHANGED
@@ -76,6 +76,8 @@
76
76
 
77
77
  ```
78
78
 
79
+ has_many :tweets
80
+
79
81
  has_many :school_tweets,class_name: 'Tweet', foreign_key: 'school_id'
80
82
 
81
83
  ```