2

I am loading some data with

data = Product.find_by_sql(sql)

so it is returning array. But, i further want to chain some model methods like order, where . I guess this is only possible if i change/convert this array into ActiveRecord::Associations::CollectionProxy object.

How can i ?

4
  • shouldn't you be doing that in your sql, that will make it efficient and reduce the overhead of data manipulation after fetching. Commented May 29, 2014 at 15:34
  • yes, i agree but that is not the condition. The above question is not the actual code. It is much more complex. I often came across such situation where i have do do this. Commented May 29, 2014 at 15:36
  • I don't think you can convert an array object to a CollectionProxy Commented May 29, 2014 at 15:47
  • It's possible if you have the object id. Look at: stackoverflow.com/questions/17331862/… Commented Apr 29, 2019 at 20:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.