请帮助我需要这个sql的ruby活动记录查询:
SELECT `properties`.* FROM `properties` INNER JOIN `recentviews` ON `recentviews`.`property_id` = `properties`.`id` WHERE `recentviews`.`user_id` = 2 ORDER BY `recentviews`.`view_time` DESC
答案 0 :(得分:1)
试试这个:
Property.joins(:recentviews).where(recentviews: {user_id: 2}).order("recentviews.view_time DESC")