I have a sql server view with the following columns
JobAdId
PositionTitle
CompanyID
ExpirationDate
I have a rails company model with the following properties along with a few more.
external_id
user_id
name
My sql server model is defined as...
class ExpiringJob < ActiveRecord::Base
establish_connection :jobdb
self.table_name = "vwExpiringJobs"
self.primary_key = 'JobAdID'
end
The CompanyID field from sql server maps to the external_id property of the company model. I need to get all of the expiring jobs from sql server and join it on the company model where the user_id from company equals the logged in user. So, the traditional sql query would look something like...
select * from vwExpiringJobs inner join companies on vwExpiringJobs.CompanyID = companies.external_id where companies.user_id = 5 order by vwExpiringJobs.ExpirationDate
I'm not finding a way to do a join with the sql server adapter and if that functionality is not possible, what is the next best way to accomplish this? Thanks.