我確定這已經被問過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