mardi 13 juin 2017

How can I create ActiveRecord for the following sql

How can I create an ActiveRecord Query for the following Sql query

SELECT device1.*
FROM devices device1
WHERE device1.id = (SELECT MAX(device2.id)
                 FROM devices device2
                 WHERE device2.user_id = device1.user_id);

I have Device model with user_id column

I dont want to user find_by_sql because it returns Array instead ActiveRecord Array

Aucun commentaire:

Enregistrer un commentaire