I use ActiveRecord in Rails 3 to retrieve data from two different tables in two different databases. These databases cannot connect to each other, but I need to make a simple connection after the fact. I would like to keep the relationship so that I can tie it along the line.
here is a simplified version of what I'm doing
browsers = Browser.all
So, as you can see, I want to join browsers with respect to events , where browser_id should equal browsers.name . events is a relation, and I can still add line-by-line sentences to it, so I donβt want to run a db request yet. How to do it?
Edit
For those who would like to see some kind of code for the answer, which I accepted below, here is what I came up with:
class EventLog < ActiveRecord::Base belongs_to :browser def get_todays_events Event.where(:row_date=>Date.today).select(:name, :browser_id).includes(:browser) end end
will allow me to get the browser name as follows
get_todays_events.browser.name
source share