class Visitor has_many :sessions end class Session belongs_to :visitor belongs_to :site end class Site has_many :sessions end
I would like to visit the site on the site every day. Since the visitor is not directly connected to the site, but the session, I need to get all the sessions for a particular site, group by day, and then group by visitor_id. Here are some sample data (sorted by created_at ASC):
visitor_id site_id created_at 6 3 2011-09-27 6 3 2011-09-27 7 3 2011-09-27 2 3 2011-09-29 7 3 2011-09-29
Ideally, I should see that since 09/27 there have been 2 unique visitors, and on 09/29 there have also been 2 unique visitors. I tried this:
Session.group('date(created_at)').group('visitor_id').size
But I get this in return (which is wrong):
Thanks guys!
source share