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

时间:2015-03-16 10:55:42

标签: php cakephp model-view-controller foreign-key-relationship

我有2个控制器

  1. 客户
  2. 门票
  3. Model Customer.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')
                        );
    

    但它不起作用。

1 个答案:

答案 0 :(得分:0)

$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')
                    );

只需尝试以上查询并分享结果即可。