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

質問編集履歴

3

文法の修正

2020/07/30 12:26

投稿

rrtts667
rrtts667

スコア18

title CHANGED
File without changes
body CHANGED
@@ -126,4 +126,50 @@
126
126
  end
127
127
  ```
128
128
 
129
- も入れた方がよろしいでしょうか?
129
+ も入れた方がよろしいでしょうか?
130
+
131
+
132
+ 追加
133
+ rails migrateを行なった時に
134
+ 以下のようになります。
135
+ ```rails
136
+ ActiveRecord::Schema.define(version: 2020_07_30_062001) do
137
+
138
+ create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
139
+ t.integer "user_id"
140
+ t.integer "tweet_id"
141
+ t.text "text"
142
+ t.datetime "created_at", precision: 6, null: false
143
+ t.datetime "updated_at", precision: 6, null: false
144
+ end
145
+
146
+ create_table "favorites", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
147
+ t.datetime "created_at", precision: 6, null: false
148
+ t.datetime "updated_at", precision: 6, null: false
149
+ end
150
+
151
+ create_table "tweets", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
152
+ t.string "title"
153
+ t.string "text"
154
+ t.string "image"
155
+ t.datetime "created_at", precision: 6, null: false
156
+ t.datetime "updated_at", precision: 6, null: false
157
+ t.integer "user_id"
158
+ end
159
+
160
+ create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
161
+ t.string "email", default: "", null: false
162
+ t.string "encrypted_password", default: "", null: false
163
+ t.string "reset_password_token"
164
+ t.datetime "reset_password_sent_at"
165
+ t.datetime "remember_created_at"
166
+ t.datetime "created_at", precision: 6, null: false
167
+ t.datetime "updated_at", precision: 6, null: false
168
+ t.string "nickname"
169
+ t.index ["email"], name: "index_users_on_email", unique: true
170
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
171
+ end
172
+
173
+ end
174
+
175
+ ```

2

文法の修正

2020/07/30 12:26

投稿

rrtts667
rrtts667

スコア18

title CHANGED
File without changes
body CHANGED
@@ -85,4 +85,45 @@
85
85
 
86
86
  end
87
87
 
88
- ```
88
+ ```
89
+
90
+ favoriteモデル
91
+ ```rails
92
+ class Favorite < ApplicationRecord
93
+ belongs_to :user
94
+ belongs_to :tweet
95
+ end
96
+
97
+ ```
98
+
99
+ こちらになります。
100
+
101
+ 関連した記事のスキーマーの記載の箇所に
102
+ ```rails
103
+ schema.rb
104
+ create_table "users", force: :cascade do |t|
105
+ (略)
106
+ end
107
+ create_table "products", force: :cascade do |t|
108
+ (略)
109
+ end
110
+
111
+ create_table "favorites", force: :cascade do |t|
112
+ t.integer "user_id", null: false
113
+ t.integer "product_id", null: false
114
+ t.datetime "created_at", null: false
115
+ t.datetime "updated_at", null: false
116
+ end
117
+ ```
118
+
119
+ とありますがもしかしたら
120
+ ```rails
121
+ create_table "users", force: :cascade do |t|
122
+ (略)
123
+ end
124
+ create_table "products", force: :cascade do |t|
125
+ (略)
126
+ end
127
+ ```
128
+
129
+ も入れた方がよろしいでしょうか?

1

文法の修正

2020/07/30 12:19

投稿

rrtts667
rrtts667

スコア18

title CHANGED
File without changes
body CHANGED
@@ -38,4 +38,51 @@
38
38
  ```
39
39
 
40
40
  ご教授願えたら幸いです。
41
- よろしくお願いします。
41
+ よろしくお願いします。
42
+
43
+ 追加
44
+
45
+ スキーマー
46
+ ```rails
47
+ ctiveRecord::Schema.define(version: 2020_07_14_100939) do
48
+
49
+ create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
50
+ t.integer "user_id"
51
+ t.integer "tweet_id"
52
+ t.text "text"
53
+ t.datetime "created_at", precision: 6, null: false
54
+ t.datetime "updated_at", precision: 6, null: false
55
+ end
56
+
57
+ create_table "tweets", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
58
+ t.string "title"
59
+ t.string "text"
60
+ t.string "image"
61
+ t.datetime "created_at", precision: 6, null: false
62
+ t.datetime "updated_at", precision: 6, null: false
63
+ t.integer "user_id"
64
+ end
65
+
66
+ create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
67
+ t.string "email", default: "", null: false
68
+ t.string "encrypted_password", default: "", null: false
69
+ t.string "reset_password_token"
70
+ t.datetime "reset_password_sent_at"
71
+ t.datetime "remember_created_at"
72
+ t.datetime "created_at", precision: 6, null: false
73
+ t.datetime "updated_at", precision: 6, null: false
74
+ t.string "nickname"
75
+ t.index ["email"], name: "index_users_on_email", unique: true
76
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
77
+ end
78
+
79
+ create_table "favorites", force: :cascade do |t|
80
+ t.integer "user_id", null: false
81
+ t.integer "tweet_id", null: false
82
+ t.datetime "created_at", null: false
83
+ t.datetime "updated_at", null: false
84
+ end
85
+
86
+ end
87
+
88
+ ```