ActiveRecord View subclass? -- Helper table lookups


#1

Hi,

I’ve read the rails book and wiki entries such as
http://wiki.rubyonrails.org/rails/pages/HowtoUseJoinsWithFindAll

As far as I can tell, the recommended way to display the author’s name
for a db of posts / authors is to use :include and then use

post.author.full_name to see the full_name column.

But:
a) all columns of author are pulled down
b) Not clear to me how you’d cleanly iterate through the desired result
columns in the ‘post’ object since one of the desired columns is
‘author.full_name’
(Any comments on the above?)

So IMHO, we need a ‘View’ subclass of ActiveRecord that takes a sql
statement and returns the result as an object. The resulting object
would support all of the read-only methods and properties of the usual
ActiveRecord db model objects.
It would be used when the db doesn’t support views. (Eg MySql v4.x)

Unfortunately, ActiveRecord::Base.connection.select_all sql only returns
an array of hashes. This could be better. Eg render partial/collection
will NOT step through the array elements (the rows).

==>> Comments? Anyone worked on this? Tips for me to start with?

Thanks,

Larry