0
我有一個名爲DueAction的表,它有一個DueEmployeeDetail的引用。只有當引用DueEmployeeDetail表的DueAction表的所有條目都爲true時,我才需要更新DueEmployeeDetail的is_confimed列。如果有5個條目並且只有3個爲真,則is_confirmed不能更新爲true。在rails中查找True值
in model i have written this :-
def is_exist(due_employee_detail)
\t # byebug
\t flag = 0
DueAction.exists?(is_confirm: true,due_employee_detail_id: due_employee_detail)
flag
end
in controller i have wriien this:-
if @due_action.is_exist(@due_action.due_employee_detail_id)
DueEmployeeDetail.where(id: @due_action.due_employee_detail_id).update_all(is_confirmed: true)
else
end
but its not working.Its checking only true not checking whether all are true or not.
以及如何在控制器中訪問此方法? –
此方法包含在DueEmployeeDetails「生命週期」中。每當你打電話保存時,這個回調就會自動運行。 'due_employee_detail = DueEmployeeDetail.find(some_id) due_employee_detail.save' 將觸發提及的邏輯 – Codextremist