I need Ruby active record query for this SQL:
SELECT `properties`.* FROM `properties`
INNER JOIN `recentviews` ON `recentviews`.`property_id` = `properties`.`id`
WHERE `recentviews`.`user_id` = 2 ORDER BY `recentviews`.`view_time` DESC
Try this:
Property.joins(:recentviews).where(recentviews: {user_id: 2}).order("recentviews.view_time DESC")