0

database design

I have this problem when I create phps with cake bake In cakephp.I have the following problem: if I keep two elements in libraries, one with id 1 and othe id 2.then I saved an item in rooms with library_id= 1,and after another item in rooms with library_id= 2. I really can relate room element with the element of user. This should not afford it since they have the same library_id.So it does not refer to the same library. I need only user can relate to room if they refer to the same library.I try that cakephp throws error, or do not allow the relationship, when users and rooms not have the same library_id,how I can do this?

result tables:

libraries         users               rooms                 users_rooms
id            id   library_id       id   library_id        user_id   room_id
1             1       1             1       2                1           1
2
4

1 回答 1

1

如果他们引用同一个库,我只需要用户可以与房间相关联。我怎么能这样做?

通常,菱形的两个“边”必须从“底部”到同一个“根”的菱形依赖关系需要使用识别关系:

在此处输入图像描述

请注意如何library_id从“根”迁移到菱形的“两侧”,然后在表中的“底部”合并users_rooms。这样,如果用户连接到房间,他们都必须连接到同一个库。

不幸的是,我不熟悉 CakePHP,所以我不知道它是否支持这一点。

于 2013-01-28T13:44:28.637 回答