how do I use ActiveRecord for selects that return data across multiple tables, or a database view? (ActiveRecord::Base.connection.select gives me a : NoMethodError: private method `select')

Hi,

If I want to return SQL data that cuts across multiple models (e.g.
not specific to one mode) how do I do this? Actually the use case
could be either (a) custom SQL I want to call or via (b) SQL call to a
database view I've created?

The select method
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#M001704
seems to be what I need however when I try to use this I'm getting an
error:

ActiveRecord::Base.connection.select("select * from categories")

NoMethodError: private method `select' called for
#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x253710c>
        from (irb):11

Greg Hauptmann wrote:

Hi,

If I want to return SQL data that cuts across multiple models (e.g.
not specific to one mode) how do I do this? Actually the use case
could be either (a) custom SQL I want to call or via (b) SQL call to a
database view I've created?

If I understand your question then the way to do this is through
associations defined in your model. You can have more than one
association defined between identical tables, each with a different name
and select conditions.

See:
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

ok - I see I can do the following

   ActiveRecord::Base.connection.select_all('select * from categories')

and get a hash back