0

我在 CakePHP 1.3 文档中读到conditions参数 forfind()等同于 SQLWHERE子句。我正在尝试在 CakePHP 中写这样的东西:

 select count(*) from claim 
 where ((claim_id = X and company_id = W) or (claimant_firstName = Y and claimant_lastName = Z))

但是,我对如何构造conditions参数感到困惑。

是不是像

 find('count', array(
            'conditions' => array(
                              Claim.company_id => $companyId,
                              Claim.id' => $claimNumber,
                             'or' => array(
                                     'Claimant.first_name' => $claimantFirstName,
                                     'Claimant.last_name' => $claimantLastName,
                                     )
                           )
              )
     );

或者

     find('count', array(
            'conditions' => array(
                             'or' => array(
                                        Claim.company_id => $companyId,
                                        Claim.id' => $claimNumber
                                     )
                             'or' => array(
                                     'Claimant.first_name' => $claimantFirstName,
                                     'Claimant.last_name' => $claimantLastName,
                                     )
                           )
              )

还是完全不同的东西?

4

1 回答 1

1

尝试这个:

  $conditions =  array(
                   'or' => array ( 
                       array( 'and' => array( 'Claim.company_id' => $companyId, 'Claim.id' => $claimNumber )), 
                       array( 'and' => array( 'Claimant.first_name' => $claimantFirstName, 'Claimant.last_name' => $claimantLastName )) 
                   )
                 );
  $this->ModelName->find('count', array( 'conditions' => $conditions ));
于 2013-08-14T16:22:26.737 回答