これはすでに何百万回も尋ねられていると思います。よく検索していないだけです。次の設定があります: 多くのイベントを持つインストラクターがいます。各イベントにはインストラクター (所有者/作成者) が 1 人しかいません。別のリンケージを追加して、他のインストラクターを関連付けることができるようにしたいが、元のインストラクター (所有者) は保持したい。私は大雑把な ASCII 表現を持っていますが、私の人生では Rails モデルでそれを行う方法を理解することはできません。
,-------------------.
| other_instructors |
|-------------------|
| event_id |-------------.
,---------------| instructor_id | |
| `-------------------' |
| ,---------------------. |
`->>| instructor |<--. |
|---------------------| | ,------------. |
| name | | | event |<-'
| email | | |------------|
| office | | | title |
| phone | | | location |
| admin? | | | benefit |
| notify_recipient? | | | notes |
| new_user? | | | start_time |
| (acts_as_authentic) | | | end_time |
`---------------------' | | live_in? |
`---| instructor |
`------------'
@instructor.events = [... array of events ...]
@associated_events = [... array of events associated but not owned via other_instructors table ...]
@event.instructor = ... One Instructor ...
@event.other_instructors = [... array of other instructors ...]