我是CakePHP的新手,我正在尝试为结果构建复杂的查询。它杀了我。也许some1可以帮助我。 我使用蛋糕2.7
我有两个表有3个关系(多对多)。 Neighbourhood
和Polygon
。
案例看起来像Neighbourhood
有很多Neighbourhoods
,它也属于许多Neighbourhoods
。此外,Neighbourhood
有许多Polygons
和Polygon
属于mnay Neighbourhoods
。
Neighbourhood
表包含2个字段name
和zip
。我从用户那里得到的是zip code
。
现在我想要的是:
我想从Polygons
及其Neighbourhood
获取所有Neighbours
。 Neighbourhood.zip = defined by user
。
我该怎么做?我应该编写自定义查询或将proccess分成更小的步骤吗?我整天都在和这个人打架。
以下是模型关系的外观:
class Neighbourhood extends AppModel
{
var $hasAndBelongsToMany = array(
'Neighbourhoods' => array(
'className' => 'Neighbourhood',
'joinTable' => 'neighbourhoods_neighbours',
'foreignKey' => 'neighbourhood_id',
'associationForeignKey' => 'neighbour_id',
'unique' => false
),
'Polygon' => array(
'className' => 'Polygon',
'joinTable' => 'neighbourhoods_polygons',
'foreignKey' => 'neighbourhood_id',
'associationForeignKey' => 'polygon_id',
'unique' => false
),
);
}
class Polygon extends AppModel
{
var $hasAndBelongsToMany = array(
'Neighbours' => array(
'className' => 'Neighbourhood',
'joinTable' => 'neighbourhoods_polygons',
'foreignKey' => 'polygon_id',
'associationForeignKey' => 'neighbourhood_id',
'unique' => false,
)
);
}