簡體   English   中英

使用Active Record進行Rails關系查詢

[英]rails Relationship Query with Active Record

聊天(ID,狀態,名稱)chat_participations(ID,狀態,用戶ID)

如果要計算多少用戶的chat_participations是status ='unread',我該怎么辦

所以我有這個:

  @chats_unread = current_user.chat_participations.where(:status => 'unread').count

可以,但是在聊天時會中斷.status ='closed'

我只希望chat.status ='open的聊天計數

我試過了:

  @chats_unread = current_user.chat.where(:status => 'open).chat_participations.where(:status => 'unread').count

但是那個錯誤。 有想法嗎?

謝謝

嘗試將表名稱放在條件中。

where('chats.status' => 'open')
where('chat_participations.status' => 'unread')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM