sql的活动记录

时间:2016-04-21 10:52:43

标签: ruby-on-rails activerecord

请帮助我需要这个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

1 个答案:

答案 0 :(得分:1)

试试这个:

Property.joins(:recentviews).where(recentviews: {user_id: 2}).order("recentviews.view_time DESC")