How to dry given query code in rails -


i have given code

@classes  = class.includes(:student_classes).where(:employee_id => current_employee.id)   @students = {}      unless @classes.blank?       @classes.each { |class|         unless class.student_classes.blank?           class.student_classes.each { |std|             @students[std.student.id] = std.student.name           }         end       }     end 

to fetch @students. please guide me how dry query. in advance.

the best way :

student   .joins(student_classes: [:class])   .where(classes: {employee_id: current_employee.id}) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -