I have a questions regarding implementation of a system that will send messages to subgroups of people held in a database.
The [potential] message Recipients are held in a table. Each Recipient record has a set of column booleans indicating whether they are a member of a particular group or not: msg_group_1:boolean, msg_group_2:boolean, etc. Recipients may belong to more than one group.
There is also a Message table, where each message record has a corresponding set of booleans for indicating which groups the message is intended for.
Then, when a new message is composed, the form includes a checkbox to indicate which groups the message is intended for.
To implement the Send, I then need to find all members of the Recipients table that belong to any of the groups that the new Message is intended for.
I can’t use,
Recipients.find(:all, :conditions => ['msg_group_1 = ? OR msg_group_2 = ?', @message.msg_group_1, @message.msg_group_2])
…as this will match records where the booleans are equal, even if the pair are booleans are both false (obviously I only want cases where both flags are true).
Is there an efficient way to ‘find’ these using a SQL search, or some other Ruby on Rails trick that will obtain the matching records where both flags are true?
Thanks.
OK, This question has been open for 5 months at time of writing, and no-one has offered a solution so the ‘answer’ seems to be that this is not possible.