You doubt conditions in cakephp?

Asked

Viewed 34 times

1

I’m trying to make a conditions in a find. I have 2 tables: tipopessoas and pessoas, on the table pessoas I have a foreign key for table tipopessoas. I want my find to bring the result only to two types of people, RESPONSAVEL and PROFESSOR, for this I’m trying to use a find with conditions using OR, but only one result returns.

How to make it return the 2 types of people and not just 1 ?

I’m trying like this.

$this->set("pessoas", $this->User->Pessoa->find('list', array(
                                                        'fields' => array("Pessoa.id", "Pessoa.nome", "Pessoa.tipopessoas_id",'Tipopessoa.id','Tipopessoa.descricao'),
                                                        "conditions"=>array("OR"=>array('Tipopessoa.descricao = '=>'RESPONSAVEL', 
                                                                                        'Tipopessoa.descricao = '=>'PROFESSOR')),
                                                        'recursive' => 0))); 

1 answer

2


Great, you’re almost there. What you have to do is something like:

"conditions"=>array("OR"=>array(
    array('Tipopessoa.descricao' =>'RESPONSAVEL'),
    array('Tipopessoa.descricao' =>'PROFESSOR') )
 )

another method you can use is:

"conditions"=> array('Tipopessoa.descricao' => array('RESPONSAVEL', 'PROFESSOR'));
  • perfect, thank you very much !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.