Rails find_by_sql not returning results

196 Views Asked by At

So my query I am running is returning an array with an id and nothing else. But when I run the same query in psql it returns back the correct records. Any idea why this could be, or if there may be a better way of executing this query?

rails console

numbers = RoboDial.find_by_sql "SELECT p.id, p.nam_last, w.warn_closed_date, w.warn_date_issued, pn.phone_number, w.collection_amount FROM people p LEFT OUTER JOIN warrants w ON p.id = w.person_id LEFT OUTER JOIN pn ON p.id = pn.person_id where p.id = 81437"

Returns this which is not correct

[#<RoboDial id: 81437>, #<RoboDial id: 81437>]

Am I doing something wrong here? When I run this same query in a psql session it returns back all the correct values.

Correct values would include the below

p.id, p.nam_last, w.warn_closed_date, w.warn_date_issued, pn.phone_number, w.collection_amount

0

There are 0 best solutions below