質問編集履歴

3

f

2020/11/07 12:27

投稿

Meitoku
Meitoku

score43

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ####やりたいこと
6
6
 
7
- 検索欄にschoolsテーブルのnameカラムの値を検索すると、それに紐づくツイートを検索結果に表示させたい
7
+ 検索欄にcategoriesテーブルのnameカラムの値を検索すると、それに紐づくツイートを検索結果に表示させたい
8
8
 
9
9
 
10
10
 

2

fffffff

2020/11/07 12:27

投稿

Meitoku
Meitoku

score43

test CHANGED
File without changes
test CHANGED
@@ -16,11 +16,11 @@
16
16
 
17
17
  tweetsテーブル
18
18
 
19
- |id|text|category_id|
19
+ |id|text|school_a_id|school_b_id
20
20
 
21
- |:--|:--:|--:|
21
+ |:--|:--:|--:|--:|
22
22
 
23
- |1|おはよう|1|
23
+ |1|おはよう|1|2|
24
24
 
25
25
 
26
26
 
@@ -31,6 +31,8 @@
31
31
  |:--|:--:|
32
32
 
33
33
  |1|A高校|
34
+
35
+ |2|B高校
34
36
 
35
37
 
36
38
 
@@ -52,11 +54,123 @@
52
54
 
53
55
  end
54
56
 
57
+
58
+
59
+ validates :title_info,length: {maximum: 30}
60
+
61
+ validates :tournament_id,:school_a,:school_b,:school_a_score,:school_b_score,:text,:title_info ,presence: true
62
+
63
+ mount_uploader :image, ImageUploader
64
+
55
- belongs_to :category
65
+ belongs_to :user
66
+
67
+ has_many :category
68
+
69
+ has_many :comments
70
+
71
+ has_many :likes,dependent: :destroy
72
+
73
+ has_many :liked_users,through: :likes,source: :user
74
+
75
+ has_many :notifications,dependent: :destroy
76
+
77
+ belongs_to :school_a,class_name: 'Category', foreign_key: 'school_a_id'
78
+
79
+ belongs_to :school_b,class_name: 'Category', foreign_key: 'school_b_id'
80
+
81
+ belongs_to :tournament,class_name: 'Category', foreign_key: 'tournament_id'
56
82
 
57
83
  ```
58
84
 
85
+ category.rb
86
+
87
+
88
+
89
+ ```
90
+
91
+ class Category < ApplicationRecord
92
+
59
- category.rbにはhas_many :tweets
93
+ has_many :tweets
94
+
95
+ has_many :analyses
96
+
97
+ has_many :forecasts
98
+
99
+ has_ancestry
100
+
101
+ has_many :school_a_tweets,class_name: 'Tweet', foreign_key: 'school_a_id'
102
+
103
+ has_many :school_b_tweets,class_name: 'Tweet', foreign_key: 'school_b_id'
104
+
105
+ has_many :tournament_tweets,class_name: 'Tweet', foreign_key: 'tournament_id'
106
+
107
+ has_many :school_analyses,class_name: 'Analysis', foreign_key: 'school_id'
108
+
109
+ has_many :tournament_analyses,class_name: 'Analysis', foreign_key: 'tournament_id'
110
+
111
+ has_many :win_school_forecasts,class_name: 'Forecast', foreign_key: 'win_school_id'
112
+
113
+ has_many :lose_school_forecasts,class_name: 'Forecast', foreign_key: 'lose_school_id'
114
+
115
+ has_many :tournament_forecasts,class_name: 'Forecast', foreign_key: 'tournament_id'
116
+
117
+ end
118
+
119
+ ```
120
+
121
+
122
+
123
+ schema
124
+
125
+ ```
126
+
127
+ create_table "categories", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
128
+
129
+ t.string "name"
130
+
131
+ t.string "ancestry"
132
+
133
+ t.datetime "created_at", null: false
134
+
135
+ t.datetime "updated_at", null: false
136
+
137
+ end
138
+
139
+
140
+
141
+ create_table "tweets", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
142
+
143
+ t.string "title_info"
144
+
145
+ t.text "text"
146
+
147
+ t.text "image"
148
+
149
+ t.integer "school_a_score"
150
+
151
+ t.integer "school_b_score"
152
+
153
+ t.datetime "created_at"
154
+
155
+ t.datetime "updated_at"
156
+
157
+ t.bigint "school_a_id", null: false
158
+
159
+ t.bigint "school_b_id", null: false
160
+
161
+ t.bigint "tournament_id", null: false
162
+
163
+ t.integer "user_id"
164
+
165
+ t.index ["school_a_id"], name: "index_tweets_on_school_a_id"
166
+
167
+ t.index ["school_b_id"], name: "index_tweets_on_school_b_id"
168
+
169
+ t.index ["tournament_id"], name: "index_tweets_on_tournament_id"
170
+
171
+ end
172
+
173
+ ```
60
174
 
61
175
 
62
176
 

1

kj

2020/11/05 09:27

投稿

Meitoku
Meitoku

score43

test CHANGED
@@ -1 +1 @@
1
- Railz 検索機能 他モデル
1
+ Rails 検索機能 他モデル
test CHANGED
File without changes