Let’s say I have a model Poll which would have multiple Options. For
each Option a User can vote.
Let’s say in my particular case, certain Options are recurring. To save
database space, recurring Options such as “Yes” or “No” or “Maybe” are
stored once and then joined accordingly to relevant Polls… This makes
a HABTM setup better than a has_many setup (or at least I think it does)
Poll < ActiveRecord::Base
Option < ActiveRecord::Base
Vote < ActiveRecord::Base
The problem with this setup is that a Vote belongs to an Option, but in
respect to a specific Poll. If I just were to count the total number of
Votes for an Option normally - like @option.votes, then the total would
be for all Polls combined. But I need it to be specific to the one Poll
and can’t quite figure out the design pattern I should be using.
This would be way easier if I just used has_many, but then stuff like
“Yes” or “No” would be in the options table like a bajillion times.
Maybe my approach is wrong. Let me know!