質問編集履歴
1
・質問の意図とは関係ない問題を記載していたので削除しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,40 +66,6 @@
|
|
66
66
|
|
67
67
|
しかし、上記のサイトのコードでは下記の問題がありました。
|
68
68
|
|
69
|
-
・ActiveRecord_AssociationRelationではなく、ActiveRecord_Relationが返却されてしまうため、要素を取り出さないとモデルのメソッドを使えない。
|
70
|
-
|
71
|
-
→例えば、勤務日数を計算する下記のようなメソッドを使う場合に、ActiveRecord_Relationではmethod_missingになってしまいます。
|
72
|
-
|
73
|
-
(ActiveRecord_AssociationRelationは配列内の要素全てのattendance_countの合計を返します)
|
74
|
-
|
75
|
-
```Ruby
|
76
|
-
|
77
|
-
def attendance_count
|
78
|
-
|
79
|
-
return 0 if status.nil?
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
case status.value
|
84
|
-
|
85
|
-
when 0, 10, 11 # 出勤系のステータス
|
86
|
-
|
87
|
-
1
|
88
|
-
|
89
|
-
when 4, 5, 6, 7, 8, 9 # 半休系のステータス
|
90
|
-
|
91
|
-
0.5
|
92
|
-
|
93
|
-
else # 休暇、欠勤
|
94
|
-
|
95
|
-
0
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
```
|
102
|
-
|
103
69
|
・リファクタリング前よりも、総コード量は増加する。(問題かはわかりませんが。。。)
|
104
70
|
|
105
71
|
|