jeudi 23 août 2018

How can i use complex direct query instead of activerecord in a rails application?

I have one rails application, which has one function that read values from database using active-record like this way

def get_all_products
 products = Product.for_locations(location_id)
 products.includes(:a, { b: [:c]}, {d: [:e]}, :f).each do |product|  
   product_forms = product.product_forms.sort_by{ |a| a[:sequence_no] } 
   .......
   .......
 end
end

this above function will take some time to process so this running as a background job. Now i would like to move this portion to a separate rails API application, so that will process and put that data in database, but this new application doesn't have any models and all, so how can i use this same function get_all_products in new rails API application, there i can't use active-record to get the data because there is no model, and even if i use direct query, its bit complicated, is there any way to achieve this?

Aucun commentaire:

Enregistrer un commentaire