モデル
profile.rb
has_one :schedules
schedule.rb
belongs_to :profile
DB
profiles
id | name |
---|---|
1 | Tomoko |
2 | Natsumi |
schedules
id | profile_id | time |
---|---|---|
1 | 1 | 2017-07-16 |
2 | 2 | 2017-07-18 |
3 | 2 | 2017-07-19 |
上記の設定で、
Schedule.profile.nameのようにして、scheduleをもとにユーザー名を取得したいと考えています。
現在、上記のようにするとnilが返ってきます。
どのようにすればよろしいでしょうか。
ご教授お願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。