質問編集履歴
1
修正依頼箇所記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,71 @@
|
|
127
127
|
・ruby 2.5.1p57
|
128
128
|
|
129
129
|
・postgreSQL
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```Ruby
|
134
|
+
|
135
|
+
class User < ApplicationRecord
|
136
|
+
|
137
|
+
# Include default devise modules. Others available are:
|
138
|
+
|
139
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
140
|
+
|
141
|
+
devise :database_authenticatable, :registerable,
|
142
|
+
|
143
|
+
:recoverable, :rememberable, :validatable
|
144
|
+
|
145
|
+
validates :name, presence: true, uniqueness: true
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
has_many :family_users
|
150
|
+
|
151
|
+
has_many :families, through: :family_users
|
152
|
+
|
153
|
+
has_many :records
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
```Ruby
|
164
|
+
|
165
|
+
class Record < ApplicationRecord
|
166
|
+
|
167
|
+
belongs_to :family
|
168
|
+
|
169
|
+
belongs_to :user
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
validates :user_id, presence: true
|
174
|
+
|
175
|
+
validates :value, presence: true
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
```Ruby
|
184
|
+
|
185
|
+
class Family < ApplicationRecord
|
186
|
+
|
187
|
+
has_many :family_users
|
188
|
+
|
189
|
+
has_many :users, through: :family_users
|
190
|
+
|
191
|
+
has_many :records
|
192
|
+
|
193
|
+
validates :name, presence: true, uniqueness: true
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
```
|