2017-05-31 33 views
0

ň後我有UserPost模型has_many<=>belongs_toRails的查詢超過每日期

我需要找到用戶其中超過每天n個崗位

我這樣做只是這個查詢有可以讓我找到用戶比N更多的帖子

User.select('users.*, count(posts.id)').joins(:posts).group('posts.id').having('count(posts.id) > 1') 

如何更新我的查詢?

回答

0

User.select('users.*, count(posts.id)').joins(:posts). 
group('users.id'). 
having('count(posts.id) >= 1'). 
where("DATE(posts.created_at) = ?",Date.today) 
0

實現這裏嘗試

User.select('users.*'). 
joins(:posts). 
group('posts.created_at::date'). 
having('count(posts.id) > 1'). 
order('posts.created_at::date desc') 

的差異,是由天分組,而不是由數後的分組。