How do I do a join in ActiveRecord after records have been returned?

Posted by Russ Bradberry on Stack Overflow See other posts from Stack Overflow or by Russ Bradberry
Published on 2010-06-08T15:17:43Z Indexed on 2010/06/08 15:22 UTC
Read the original article Hit count: 229

I am using ActiveRecord in Rails 3 to pull data from two different tables in two different databases. These databases can not join on each other, but I have the need to do a simple join after-the-fact. I would like to preserve the relation so that I can chain it down the line.

here is a simplified version of what I am doing

browsers = Browser.all # <-- this is fairly small and can reside in memory
events = Event.where(:row_date=>Date.today).select(:name, :browser_id)

So as you can see, I want to join browsers in on the events relation, where browser_id should equal browsers.name. events is a relation and I can still add clauses to it down the line, so I dont want to run the query on the db just yet. How would I accomplish this?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby