Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.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
Php 获取没有(HABTM)关联数据的数据_Php_Cakephp_Cakephp 2.3 - Fatal编程技术网

Php 获取没有(HABTM)关联数据的数据

Php 获取没有(HABTM)关联数据的数据,php,cakephp,cakephp-2.3,Php,Cakephp,Cakephp 2.3,我有一个良好的HABTM关系,当我在Foo上执行find()时,我得到如下结果: { "Foo": { "ID": "32", ... }, "Bar": [ { "ID": "3", ... }, { "ID": "4", ... } ] } …但在某些情况下,我只想获

我有一个良好的HABTM关系,当我在
Foo
上执行
find()
时,我得到如下结果:

{
    "Foo": {
        "ID": "32",
        ...
    },
    "Bar": [
        {
            "ID": "3",
             ...
        },
        {
            "ID": "4",
            ...
        }
    ]
}
…但在某些情况下,我只想获得
Foo
,而不需要相关的
(甚至不需要查询
)。我该怎么做

我试过:

$this->{$this->modelClass}->find('all', array('fields' => array($this->modelClass.'.*')));
…但这没用

如果有关系,我的模型是:

class Foo extends AppModel {
    public $primaryKey = "ID";

    public $hasAndBelongsToMany = array(
            'Bar' =>
            array(
                    'className' => 'Bar',
                    'joinTable' => 'bars_foos',
                    'foreignKey' => 'foo_ID',
                    'associationForeignKey' => 'bar_ID'
            )
    );
}
class Bar extends AppModel {
    public $primaryKey = "ID";

    public $hasAndBelongsToMany = array(
        'Foo' =>
            array(
                'className' => 'Foo',
                'joinTable' => 'bars_foos',
                'foreignKey' => 'bar_ID',
                'associationForeignKey' => 'foo_ID'
        )
    );
}

经过一些挖掘,我在模型属性文档中发现了以下内容:

在我的例子中,
Model->find('all',array('recursive'=>-1))
正在做我想做的事情