0

我有以下数据库关系:

Building hasMany Shape

Appartment hasOne Shape

Building hasMany Appartment

Shape belongsTo Building & Appartment

现在,在 Shape 模型中,我想检索属于某个建筑物的所有形状。这包括属于该特定建筑物的公寓的形状。

例如

Building 'X'

There are 4 shapes directly linked to building X via the belongsTo Building relation. Shape->Building

And there are 2 shapes directly linked to 2 appartments via the belongsTo Appartment relation. These 2 appartments again are directly linked to Building X via the belongsTo Building relation. Thus these 2 shapes are indirectly linked to building X. Shape->Appartment->Building

我似乎无法理解这一点,非常感谢您的帮助。

4

4 回答 4

2

使用CakePHP 的 Containable Behavior

于 2012-04-04T14:06:13.607 回答
0

您可能还想重新考虑将形状用作自己的表格。

例如,如果您的表只有一个正确的并且看起来像这样:

shapes
id     int
shape  varchar 50

而是这样做:

buildings
id    int
bulding_number  int
shape varchar 50
...
appartments
id    int
appartment_number  int
shape varchar 50
...

在建筑物和公寓桌子上正确选择形状会更容易。您的数据库将更简单、更快,并且可能更容易编程。

但是,如果您要捕获其他形状属性,请继续。

于 2012-05-04T19:11:53.667 回答
0

尝试在你的发现中提高你的递归价值

于 2012-04-04T14:28:37.873 回答
0

您可以在函数中使用该'threaded'子句。 请参阅此处的语法示例:http: //book.cakephp.org/1.3/view/1018/findfind

它将给出父子关系中的所有依赖数据

于 2012-09-15T06:59:48.917 回答