回答編集履歴
2
不足していたアソシエーションを追加
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def latest_body_weight_record
|
10
|
-
latest_diary&.weight_record
|
10
|
+
latest_diary&.body_weight&.weight_record
|
11
11
|
end
|
12
12
|
end
|
13
13
|
```
|
1
latest_diaryメソッドを定義してそれを使うように変更
answer
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
こんな感じではどうでしょうか。
|
1
|
+
(効率は良くないかもしれませんが)こんな感じではどうでしょうか。
|
2
2
|
|
3
3
|
```ruby
|
4
4
|
class User
|
5
|
+
def latest_diary
|
6
|
+
diaries.order(created_on: :desc).first
|
7
|
+
end
|
8
|
+
|
5
9
|
def latest_body_weight_record
|
6
|
-
|
10
|
+
latest_diary&.weight_record
|
7
11
|
end
|
8
12
|
end
|
9
13
|
```
|