lundi 20 février 2023

How can I rewrite the rails to optimize the code without using unnecessary loop

I want to remove the below loop from rails code.

list=Student.find_by_sql("select study_id from students where id in (1,2,3,4,5)") 

list.each do |val|
  Subject.where(:sub_id=>val).update({:sub_code=> 'SO1'})
end

How can I rewrite these code without looping list and directly pass list in where condition?

Aucun commentaire:

Enregistrer un commentaire