Forum: Ruby on Rails ActiveRecord View subclass? -- Helper table lookups

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
390febab9477cf3b054bdeb452afc5dc?d=identicon&s=25 Larry Kluger (Guest)
on 2006-03-02 22:00
Hi,

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

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
This topic is locked and can not be replied to.