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
Post a Comment