我有两个模型,区域和区域。我无法弄清楚为什么Cake的发现不允许我从相关表中指定字段。
这些条件,只请求第一个表中的字段正常工作。
$conditions = array('fields' => array('Zone.id','Zone.title','Zone.color'));
这些情况会导致问题,因为......原因?
$conditions = array('fields' =>
array('Zone.id','Zone.title','Zone.color','Region.id','Region.title'));
基本查询,这就是我使用条件的方式。
$result = $this->Zone->find('all',$conditions);
SQL Cake正在生成:
SELECT "Zone"."id" AS "Zone__id", "Zone"."title" AS "Zone__title", "Zone"."color"
AS "Zone__color", "Region"."id" AS "Region__id", "Region"."title" AS "Region__title"
FROM "public"."zones" AS "Zone" WHERE 1 = 1
为什么Cake假设Region.fields是Zones模型的一部分?为什么这不按预期工作?
答案 0 :(得分:2)
当您这样做时,您需要在查找中包含这两个模型。以下是我确定的工作示例:
$conditions = array('fields' =>
array('Zone.id','Zone.title','Zone.color','Region.id','Region.title'));
$this->Zone->Region->find('all',$conditions);