Question

I read in the CakePHP 1.3 documentation that the conditions parameter for find() is equivalent to the SQL WHERE clause. I'm trying to write something like this in CakePHP:

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

However, I am confused about how to structure the conditions parameter.

Is it like

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

or

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

or something else entirely?

Was it helpful?

Solution

Try this:

  $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 ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top