In Rails, what is the best way to store multiple boolean attributes in a model?

Viewed 3078

I have a model House that has many boolean attributes, like has_fireplace, has_basement, has_garage, and so on. House has around 30 such boolean attributes. What is the best way to structure this model for efficient database storage and search?

I would like to eventually search for all Houses that have a fireplace and a garage, for example.

The naive way, I suppose, would be to simply add 30 boolean attributes in the model that each corresponds to a column in the database, but I'm curious if there's a Rails best practice I'm unaware of.

8 Answers
Related