chat (id, status, name) chat_participations (id, status, user_id)
What I want to do if get a count for how many of the user's chat_participations are status = 'unread'
So I have this:
@chats_unread = current_user.chat_participations.where(:status => 'unread').count
That works ok but it breaks when there is a chat.status = 'closed'
I only want the count for chat's that are c开发者_如何学JAVAhat.status = ' open
I tried:
@chats_unread = current_user.chat.where(:status => 'open).chat_participations.where(:status => 'unread').count
but that error'd. Ideas?
Thanks
Try putting the table name in the conditions.
where('chats.status' => 'open')
where('chat_participations.status' => 'unread')
精彩评论