0

I am implementing user setting in my rails website where a user has control over who can send him notifications. The allowed classed of users who can send him information is stored in an array and can be set by the user.

How do I query users to send the notification according to the user type of the user who sent the post.

I want to do something like this.

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 回答