I am not an expert in these matters, but could you get create a view
in the database for you to use for this application, then base your
model off that? This has the added advantage of naming the view after
the Rails conventions.
If you are worried about access , create a db user with no rights.
A view would have worked, but I don’t have access to create the view.
I did end up trying the ActiveRecord model and it worked much easier
than I expected.
I have an empty ActiveRecord class that gives me the connection to the
SQL Server 2003 database and I just used
ModelClass.find_by_sql(my_query) and it works just fine. As I don’t
have any controller methods other than the one or two that I’m using
to get my data I don’t think I have to worry about any of the other
ActiveRecord bits. I was assuming that AR would get confused and try
and give me more attributes that I needed named after the horrible
legacy schema I’m using, but it returns exactly what I ask for in the
query and nothing extra.
Here’s what it ends up looking like:
class RequestQueue< ActiveRecord::Base
class RequestQueueController < ApplicationController
select fp.mrID as id,
fp.mrTITLE as title,
cr.mrID as request,
fp.mrPRIORITY as severity,
fp.mrSTATUS as status
from master14 as fp
left join master3 as cr
on fp.mrID = cr.Ticket
where fp.Hotfix = ‘on’ and fp.mrSUBMITDATE > ‘2007-01-01 00:00:00.000’
order by fp.mrID desc
@tickets = RequestQueue.find_by_sql(sql)
The end result is an object with attributes id, title, request,
severity, and status, which is all I was needing. I guess I was just
over thinking it before, thinking I needed to write my own model class
or to futz around with the raw result from DBI. It’s just,
unfortunaely, way easier than that