在 Cakephp 中,如何查找两个表之间的相关数据


In Cakephp How to find related data between two tables

我有 2 个控制器

  1. 客户

模范客户.php

public $hasMany = array(
        "Ticket" => array(
            'className' => 'Ticket',
            'foreignKey' => 'customer_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
            )
        );

现在我试图获取具有Ticket.status < 2的客户列表

并且正在客户控制器中尝试此查询。

$this->paginate = array(
                'conditions' => array(
                        "OR"=>array(
                    "Customer.created  >"=> date("Y-m-d H:i:s", strtotime("-1 month")),
                    "Ticket.status  <"=> 2,
                    )
                        ),
                    'limit' => 10,
                    'order' => array('Customer.created'=>'DESC')
                    );

但它不起作用。

$this->paginate = array(
                'conditions' => array(
                    "Customer.created  >"=> date("Y-m-d H:i:s", strtotime("-1 month")),
                   ),
                'contain' => array('Ticket' => array('conditions'=> array("Ticket.status  <" => 2))),
                    'limit' => 10,
                    'order' => array('Customer.created'=>'DESC')
                    );

只需尝试上面的查询并分享结果。