I have a table, JobTypePresetting where i find few columns not null
jtp = JobTypePresetting.arel_table
JobTypePresetting.where(jtp[:comment_text_id].not_eq(nil).or(jtp[: part_listing_id].not_eq(nil)))
and i get few records and i need to create this records as duplicate in other table
so i find presettings id in other table like
avl_presetting_ids = JobEntry.where(job_id: params["job_id"], job_type_id: params["job_type_id"], template_id: params["template_id"]).pluck(:job_type_presetting_id)
and i match and create record if presetting id is not available like
unless avl_presetting_ids.include?(presetting.id)
JobEntry.create(job_id: params["job_id"], job_type_id: params["job_type_id"], template_id: params["template_id"],
job_type_presetting_id: presetting.id, comment_text_id: presetting.comment_text_id, part_listing_id: presetting.part_listing_id,
quantity: presetting.quantity, price: presetting.price, extension: presetting.extension)
end
This happens in controller before loading, so many sql queries are being written in log. How to make this a better one?
Aucun commentaire:
Enregistrer un commentaire