我有三個表(塊,角色,用戶),其中在架構符合下列條件:CakePHP的數據庫表定義三個依賴關係
blocks have many users
users have many blocks
users have many roles, but the roles are specific to the block (and the user)
blocks have many roles, but the roles are specific to the user (and the block)
例如:
user => john
belongs to block => 'metro' with role => 'builder'
belongs to block => 'rural' with role => 'investor'
user => dan
belongs to block => 'metro' with role => 'resident'
belongs to block => 'rural' with role => 'investor'
我有一個連接表名爲block_role_user與以下列:
id block_id role_id user_id created modified
我想這將是一個hasandbelo ngstomany關係在所有三個表中。我想過要在塊和用戶之間放置一個hasandbelongstomany表,而另一個表和角色和用戶之間的表都不是很好,但是這並不能完全定義塊,角色和用戶之間的獨特關係。
我正在尋找最好的方法來解決這個問題,並感謝任何意見的建議。
我已經研究過綁定模型,但這似乎並不適用於我在這裏獨特的三部分關係。
我想過創建一個名爲blockroleuser的模型並使用標準cakephp約定來建立關係。如果這是一種可以接受的方式,您是否可以提供有關命名模型和控制器文件的指導?再次
謝謝...
我欣賞建議和解釋。你所做的所有假設在我的結尾都是正確的(用戶,塊和角色之間的特定連接;主要用於選擇(並且將用戶指定給特定塊,角色僅用於決定用戶是否可以編輯與我認爲'參與'將是一個很好的名字,但同意公約真的沒有關係只要它的準確描述和後來才能被理解 – pinned5th
順便說一句,我會盡快檢查答案是否有用,一旦我的聲望得分會允許我 - 再次感謝。 – pinned5th
不客氣... – ndm