I'm working on a Rails 5.2 project that stores and manages guest lists. I have Event
and Guest
models, and they are associated with a HABTM relationship. This works well, but there is a requirement to be able to optionally store a grouping of two guests (i.e: couples) and when adding guests to the guest list, the couple can be selected and added together, without the user having to remember which of the individual guests should be added to the guest list together, for example, when selecting guests to be added to a guest list, a user should be able to select "Sam", "Andrew", "Mary & Joseph".
What would be the best way of achieving this in ActiveRecord?
class Event < ApplicationRecord
has_and_belongs_to_many :guests
end
class Guest < ApplicationRecord
has_and_belongs_to_many :events
end
Any help would be much appreciated!
Thanks