2011-06-01 106 views
0

林在我的頭上撓我的頭。這是場景。即時通訊使用原則和YAML架構文件:兩種數據庫表格有兩種不同的方式......?

我有一個表用戶和表事件

用戶看起來是這樣的:

User: 
    columns: 
     id: 
      type: integer(7) 
     email:   
      type: string(100) 
     display_name: 
      type: string(255) 
     fb_id: 
      type: string(100) 
    relations: 
     Event: 
      type: many 
      refClass: UserEvent 

事件是這樣的:

Event: 
    columns: 
     id: 
      type: integer(7) 
     initiator_id:   
      type: integer(7) 
     loc_latitude: 
      type: decimal(11) 
     loc_longitude: 
      type: decimal(11) 
     4sq_id: 
      type: integer(11) 
    relations: 
     User: 
      type: one 
      local: initiator_id 
      foreign: id 
     User: 
      type: many 
      refClass: UserEvent 

由於你可以看到問題是這樣的:用戶(或'發起者')可以啓動許多事件,並且事件可以屬於一個用戶('發起者')。但是,一個事件也可以有許多加入它的用戶,並且用戶可以加入許多事件。

因此,事件和用戶最終以兩種不同的方式相關。這個怎麼用?是否有可能這樣做,或者我錯過了什麼?

+0

你應該寫這個答案@Tom – Beno 2011-06-01 23:03:54

回答

1

我認爲你只需要在這兩個表之間建立一個多對多的關係。 UserEvent會告訴你什麼用戶有什麼事件(反之亦然)...並通過UserEvent加入並添加WHERE user.id = event.initiator_id將允許你訪問用戶啓動的事件,假設他們也屬於這些事件。

+0

謝謝你,這似乎工作得很好! – djt 2011-06-02 17:42:02

0

你可以添加一個event_attendees表的事件ID和用戶ID作爲兩列?或者這不是問題