我确定这已经被问了一百万次了。我只是没有很好地搜索。我有以下设置:我有一个有很多事件的讲师。每个活动只有一名讲师(所有者/创建者)。我想添加一个单独的链接以允许关联其他讲师,但仍保留原始讲师(所有者)。我有一个粗略的 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 ...]