【问题标题】:cakephp sql find all fieldscakephp sql 查找所有字段
【发布时间】:2016-10-03 01:13:45
【问题描述】:

我的要求是:

$monits = $this->Monit->find('all',  array('recursive'=>'0'));

结果是:

array(
    (int) 0 => array(
        'Monit' => array(
            'id' => '1',
            'nom' => 'mon'
            'ecole_id' => '1'
        ),
        'Ecole' => array(
            'id' => '1',
            'nom' => 'ecole name'
        ),
        'Seance' => array(
            (int) 0 => array(
                'id' => '2',
                'title' => 'ele name',
                'monit_id' => '1'
            ),
            (int) 1 => array(
                'id' => '3',
                'title' => 'ele name',
                'monit_id' => '1'
            )
        )
    )
)

我只想选择“Monit and Ecole”并删除“Seance”。我该怎么做?

【问题讨论】:

    标签: sql cakephp request find cakephp-2.0


    【解决方案1】:

    使用CakePHP's Containable Behavior

    在您的 AppModel 中设置 public $recursive = -1; 也是一种很好的做法。这会将所有模型的递归级别默认为-1,这是一件好事,因为自从引入 Containable 以来,使用递归基本上被认为是不好的做法。

    “递归”是一个新颖的想法,在做博客等简单的应用程序时有一些优点,但它已被放弃甚至从 Cake 3 中删除,仅仅是因为 Containable 非常棒(且易于使用)行为是。没有理由获得比实际需要更多的数据,而递归正是这样做的。另一方面,Containable 可让您准确指定您想要的相关数据。

    【讨论】:

    • 我尝试:$monits= $this->Monit->recursive = -1; $monits= $this->Monit->find('all', array('contain' => 'Ecole.nom'));结果像 $monits= $this->Monit->recursive = -1;
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2021-12-21
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    相关资源
    最近更新 更多