Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP HABTM查找所有包含或不包含关联记录的行_Php_Mysql_Cakephp - Fatal编程技术网

CakePHP HABTM查找所有包含或不包含关联记录的行

CakePHP HABTM查找所有包含或不包含关联记录的行,php,mysql,cakephp,Php,Mysql,Cakephp,我试图在CakePHP 2.x中选择所有记录,包括或不包括相关的HABTM关系 我可以运行此查询来选择源记录和相关记录,但是否也可以获取在同一查询中没有关联记录的记录?我发现查询可以单独执行此操作,但不能在单个查询中执行 如果没有关联的记录,我希望Servicetemplatedoc为null或空,因为Servicetemplate模型是我希望所有记录的来源 $query = [ 'recursive' => -1, 'fields' => [ 'Se

我试图在CakePHP 2.x中选择所有记录,包括或不包括相关的HABTM关系

我可以运行此查询来选择源记录和相关记录,但是否也可以获取在同一查询中没有关联记录的记录?我发现查询可以单独执行此操作,但不能在单个查询中执行

如果没有关联的记录,我希望Servicetemplatedoc为null或空,因为Servicetemplate模型是我希望所有记录的来源

$query = [
    'recursive' => -1,
    'fields' => [
        'Servicetemplate.*'
        'Servicetemplatedoc.*',
    ],
    'joins' => [
        [
            'table' => 'servicetemplatedocs_to_servicetemplates',
            'alias' => 'ServicetemplatedocsToServicetempaltes',
            'type' => 'LEFT',
            'conditions' => [
                'ServicetemplatedocsToServicetempaltes.servicetemplatedoc_id = Servicetemplatedoc.id',
            ],
        ],
        [
            'table' => 'servicetemplates',
            'type' => 'INNER',
            'alias' => 'Servicetemplate',
            'conditions' => 'Servicetemplate.id = ServicetemplatedocsToServicetempaltes.servicetemplate_id'
        ],
    ]
];

$result =  $this->find('all', $query);
非常感谢

$query = [
'recursive' => -1,
'fields' => [
    'Servicetemplate.*'
    'Servicetemplatedoc.*',
],
'joins' => [        
    [
        'table' => 'servicetemplates',
        'type' => 'INNER',
        'alias' => 'Servicetemplate',
        'conditions' => 'Servicetemplate.id = ServicetemplatedocsToServicetempaltes.servicetemplate_id'
    ],
    [
        'table' => 'servicetemplatedocs_to_servicetemplates',
        'alias' => 'ServicetemplatedocsToServicetempaltes',
        'type' => 'LEFT',
        'conditions' => [
            'ServicetemplatedocsToServicetempaltes.servicetemplatedoc_id = Servicetemplatedoc.id',
        ],
    ],
];


$result =  $this->find('all', $query);
首先是Servicetemplates,然后是Servicetemplatesdocs
反转表格

感谢您的回复,但是我现在发现我得到了一个MySQL错误:SQLSTATE[42S22]:未找到列:1054未知列'ServiceTemplateDocsToServiceTemplates.servicetemplate_id'在'on子句'中有什么想法吗?添加'foreignKey'=>false,这似乎没有什么区别,很奇怪的是,更改订单后,它可以正常工作,但只返回带有链接的项目