두 개의 후속 모델 user
과 event
이 있는데, 현재 하나의 조인 테이블에서 처리됩니다. 사용자를 일정에 초대 할 수 있으며 이러한 초대는 상태가 첨부되어 있습니다. 이것은 다른 조인 테이블에 의해 처리됩니다.조인 테이블의 업데이트 열
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"
어떻게해야 (나는 내가 many_to_many을 설정 한 방법에 의한 있으리라 믿고있어)
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
내가 작성하고 관련 초대장에 액세스 할 수 있어요하지만, 변경 사항이 저장되지 않습니다 나는 이것을 모델로하여 사용자 및 이벤트 초대장의 상태를보고 설정할 수 있습니다.
관련 항목 : http://stackoverflow.com/questions/15672918/sequel-accessing-many-to-many-join-table-when-adding-association – Phrogz
다른 질문으로 답변을 만들었습니다. https : // stackoverflow .com/a/48139189/676874 여기서'add_invittion'에 추가 매개 변수를 추가하기 위해 many_to_many-relation을 어떻게 적용 할 수 있는지 볼 수 있습니다. 그러나 데이터를 얻으려면 모델이 필요합니다. – knut