[英]Mongoid querying inclusion Array
我正在我的rails網站中實現用戶設置,用戶可以控制誰可以向他發送通知。 可以向其發送信息的用戶的允許類別存儲在陣列中並且可以由用戶設置。
如何根據發送帖子的用戶的用戶類型查詢用戶發送通知。
我想做這樣的事情。
notifiable_users = User.all.or("notification_setting.posted_by" includes "sender.user_type")
假設notification_setting.posted_by
是允許的用戶類型的數組, sender.user_type
是sender.user_type
的user_type(單數,而不是數組),您可以簡單地執行:
notifiable_users = User.all.or("notification_setting.posted_by" => sender.user_type)
如果是相反的方式:
notifiable_users = User.all.or("notification_setting.posted_by".to_sym.in => sender.user_types)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.