As recommended by Carvalho paste your code into text. It will be much simpler to help you and you will get help easier and faster if you do it the right way.
About your code. One of the things I’m fixing is that you’re using SQL to scan the entire table and then handle it. Try to minimize bank efforts in the array.
Come on, I’d trade these methods for this
def students
works_students.where.not(student: nil)
end
If you have used this same concept of Students in other models for sure your performance problem will be there. However, if it is only this, then there are probably more items to be analyzed.
def program_id
Qrcode.find_by(code: self.teacher_qrcode).try(:program_id)
end
I don’t know about the rest. I’d have to take a closer look at your implementation.
I do not know better to create an association of has_one :qrcode
in the model
Teacher?
Having an association you could directly access the code by the controller so:
work.teacher.qrcode.program_id
Hello prefer to post your code in text instead of copy and paste a print of it.
– Luiz Carvalho