Larry Kluger
2006-Mar-02 21:00 UTC
[Rails] ActiveRecord View subclass? -- Helper table lookups
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 -- Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- Re: ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'Transactions::DummyDdnlTransaction'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. P
- ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'Transactions::DummyDdnlTransaction'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Pleas
- ActiveRecord: table name with spaces?
- ActiveRecord: removing validations or callbacks on a subclass
- ActiveRecord subclass with manual DB connection can’t directly access column variables.