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 ?

Paritosh Piplewar
  • 7,982
  • 5
  • 26
  • 41
  • shouldn't you be doing that in your sql, that will make it efficient and reduce the overhead of data manipulation after fetching. – Babar May 29 '14 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. – Paritosh Piplewar May 29 '14 at 15:36
  • I don't think you can convert an array object to a CollectionProxy – Babar May 29 '14 at 15:47
  • It's possible if you have the object id. Look at: https://stackoverflow.com/questions/17331862/converting-an-array-of-objects-to-activerecordrelation – count0 Apr 29 '19 at 20:43

0 Answers0