Thursday, 15 August 2013

ruby on rails - How to join hashes -



ruby on rails - How to join hashes -

hi want accomplish :

feeds = [] following_companies.each |follow| feeds = feeds + activities.where(:company_id => follow.company_id).order("created_at desc").limit(5) end feeds = feeds.order("created_at desc")

by point utilize feeds = feeds.order("created_at desc"), feeds array , throws exception saying undefined method order #<array:0x007f78032e2458>. long know where clause returns hash ( or activerecord list, please right me if wrong). think problem way initializing feeds. advise?

when throw limit on end of clause, returns array instead of arel. sort array instead of using arel method order.

feeds = feeds.sort{|f| f.created_at }

update if next companies still query can do

company_ids = following_companies.pluck(:company_id)

if array, can company_ids

company_ids = following_companies.map {|u| u.location_id }

you can 1 query, instead of looping through, feeds be

activities.where(company_id: company_ids).order("created_at desc")

i'm not sure how limit 5 each id though.

ruby-on-rails

No comments:

Post a Comment