Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord connection select from a postgresql function

I am performing this query on my function:

ActiveRecord::Base.connection.execute("SELECT * FROM organic_reports('#{@date}');")

The function is returning the following attributes:

name(string), project_id(int), report_id(int), created_at(date), stats(int)

How can I use ActiveRecord to query those results, like in a normal Rails model? Methods like (where, find etc.)

like image 359
John Avatar asked Feb 19 '26 23:02

John


1 Answers

You can always use from to define the source of the query, and then you can use the ActiveRecord query interface as you normally would.

Model.from("organic_reports('#{@date}')").where('...').group('...')
like image 166
Sean Hill Avatar answered Feb 22 '26 16:02

Sean Hill