class Attendee include DataMapper::Resource property :id, Integer, key: true property :type, Enum[ :class, :staff, :facility ] property :name, String, index: true belongs_to :location has n, :events end class Event include DataMapper::Resource property :id, Serial property :year, Integer property :week, Integer property :day, Enum[ :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday ] property :start, String property :end, String property :description, String property :classes, String, default: '' property :staff, String, default: '' property :facilities, String, default: '' belongs_to :location has n, :event_attendees has n, :attendees, through: :event_attendees, via: :attendee def <<(attendee) case attendee.type when :class self.classes = classes.split(',').push(attendee.name).join(',') when :staff self.staff = staff.split(',').push(attendee.name).join(',') when :facility self.facilities = facilities.split(',').push(attendee.name).join(',') end self.attendees << attendee end end class EventAttendee include DataMapper::Resource belongs_to :event, key: true belongs_to :attendee, key: true end