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

質問編集履歴

1

修正依頼箇所記載

2020/05/05 13:12

投稿

rr2
rr2

スコア3

title CHANGED
File without changes
body CHANGED
@@ -62,4 +62,38 @@
62
62
 
63
63
  ・Rails 5.0.7.2
64
64
  ・ruby 2.5.1p57
65
- ・postgreSQL
65
+ ・postgreSQL
66
+
67
+ ```Ruby
68
+ class User < ApplicationRecord
69
+ # Include default devise modules. Others available are:
70
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
71
+ devise :database_authenticatable, :registerable,
72
+ :recoverable, :rememberable, :validatable
73
+ validates :name, presence: true, uniqueness: true
74
+
75
+ has_many :family_users
76
+ has_many :families, through: :family_users
77
+ has_many :records
78
+ end
79
+
80
+ ```
81
+
82
+ ```Ruby
83
+ class Record < ApplicationRecord
84
+ belongs_to :family
85
+ belongs_to :user
86
+
87
+ validates :user_id, presence: true
88
+ validates :value, presence: true
89
+ end
90
+ ```
91
+
92
+ ```Ruby
93
+ class Family < ApplicationRecord
94
+ has_many :family_users
95
+ has_many :users, through: :family_users
96
+ has_many :records
97
+ validates :name, presence: true, uniqueness: true
98
+ end
99
+ ```