我确定这已经被问过100万次了。我只是搜索得不好。我有以下设置:我有一个有许多事件的讲师。每个活动只有一名讲师(所有者/创建者)。我想添加一个单独的链接以允许其他教师关联,但仍保留原始教师(所有者)。我有一个粗糙的ASCII表示,但我不能为我的生活弄清楚如何在轨道模型中做到这一点。使用has_many和has_one将两个表链接在一起?
,-------------------.
| 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 ...]
感叹。你的权利。我希望避免重组我的数据库。现在最好在推出前进行生产。 – Sukima 2010-09-15 11:56:01