I have a Meeting model which has multiple Participants. Participant has a few boolean attributes: accepted, rejected ect. I would like check all participants of a meeting if their are all accepted == true.
Is there a quick way to check all boolean attributes of child objects similar to sum method (as in total_price = items.sum(&:price) )?
I have a Meeting model which has multiple Participants. Participant has a few boolean
Share
You could use
count:And if you don’t have NULLs to worry about in your boolean column:
Or you could do it this way (as suggested by klochner) to get around the usual NULL problems and avoid a double
count:You could check several boolean columns at once too.