Use without DB data

How can I use inside one of my models without specifying
the specifics of the database connection?

So in one of my models I have something like:
m =“localhost”,“myuser”,“mypass”,“mydb”)
r = m.query("SELECT ")

How can I have that SQL statement line above use the global database
connection that I already have available to ActiveRecord?

I know another option is find_by_sql, like:
@somemodels = Somemodel.find_by_sql("SELECT ")

But I am not fetching objects with my SQL. According to the API, the
left-hand side of that statement must be model objects.

Am I right on this? Is there a way to use the global db settings
while using m = so I don’t have to write the user/pass/db
attributes inside the model?


You can use ActiveRecord::Base.connection, e.g.
ActiveRecord::Base.connection.select_all(“some nasty sql here”); and
it will return as an array of hashes.


Bingo. Exactly what I was needing.

Thanks Shawn,