0

Rails Webサイトにユーザー設定を実装しており、ユーザーは誰が通知を送信できるかを制御できます。彼に情報を送信できるユーザーの許可されたクラスは配列に格納され、ユーザーが設定できます。

投稿を送信したユーザーのユーザータイプに応じて通知を送信するようにユーザーにクエリするにはどうすればよいですか。

こういうことをしたいです。

notifiable_users = User.all.or("notification_setting.posted_by" includes "sender.user_type")
4

1 に答える 1

2

Assuming notification_setting.posted_by is an array for the allowed user types and sender.user_type is the user_type(singular, not an array) of sender, you can simply do:

notifiable_users = User.all.or("notification_setting.posted_by" => sender.user_type)

If it is the other way around:

notifiable_users = User.all.or("notification_setting.posted_by".to_sym.in => sender.user_types)
于 2012-04-17T18:41:16.143 に答える