I have two sequel models user
and event
, which is currently handled by a single join table.
Users can be invited to events, and these invitations have a status attached to them; this is handled by another join table.
class Event < Sequel::Model(:events)
many_to_many :users
many_to_many :invitations, :join_table => :events_invitations, :right_key => :user_id, :class => :User, :select=>[Sequel.expr(:users).*, :events_invitations__status]
end
class User < Sequel::Model(:users)
many_to_many :events
many_to_many :invitations, :join_table => :events_invitations, :right_key => :event_id, :class => :Event, :select=>[Sequel.expr(:events).*, :events_invitations__status]
end
I am able to create and access the associated invitations, but the changes are never saved (i'm assuming due to the way i've set up the many_to_many)
user = User.create(name: "bob")
event = Event.create(title: "super fete")
user.add_event(e)
event.add_invitation(e)
invite = user.invitations.first
# this returns a reference to the event, with the extra status column from the join table
# <Event @values={:id=>1, :title=>"fete", :owner_id=>nil, :user_id=>nil, :status=>"pending"}>
# does not actually save back to the table if I modify it...
invite[:status] = "accepted"
How should I model this so as to be able to see and set the status of invitations for users and events?