Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by Linus Oleander for Creating a feed (following) grouped by day and user that is ordered by most recent on ruby on rails

Here's is one solution.

current_user_id = current_user.idPhoto.select(%q{  user_id,   COUNT(*) no_photos,   date_trunc('day', created_at::timestamp) as what_day}).group("what_day, user_id").order("what_day DESC").where(%Q{  user_id IN (    (SELECT followable_id FROM follows where follower_id = #{current_user_id})    UNION ALL    (SELECT #{current_user_id} as followable_id)  )})

date_trunc truncates the date to a specified precision, in this case the beginning of a day. I'm not sure what follows.followable_type does in your case, but the above should work.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles