Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

How can I convert this code to raw SQL and use it in rails? Because When I deploy this code in heroku, there is a request timeout error. I think this will be faster if I use raw SQL.

@payments = PaymentDetail.joins(:project).order('payment_details.created_at desc')

@payment_errors = PaymentError.joins(:project).order('payment_errors.created_at desc')

@all_payments = (@payments + @payment_errors)

1 Answer

0 votes
by (40.4k points)

Try this code:

sql = "Select * from ... your sql query here"

records_array = ActiveRecord::Base.connection.execute(sql)

  • records_array would then be the result of your SQL query in an array which you can iterate through. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...