I have two issues for you, see which one suits you and use it, of course.
Suppose your relationship in Model PROJECTS looks like this:
public $hasAndBelongsToMany = array(
'Pessoas' => array(
'joinTable' => 'pessoas_projetos',
'foreignKey' => 'cpf', // Sua FK na tabela de relação
'associationForeignKey' => 'projeto_id', // Sua FK na tabela de relação
'conditions' => array(),
),
);
And your People are like this:
public $hasAndBelongsToMany = array(
'Projetos' => array(
'joinTable' => 'pessoas_projetos',
'foreignKey' => 'projeto_id', // Sua FK na tabela de relação
'associationForeignKey' => 'cpf', // Sua FK na tabela de relação
'conditions' => array(),
),
);
Simple Submission:
As long as your Model is related to both parts (from People to Projects to Projects to People), it is simple, just to do the direct query in the Model People passing in the CPF condition, something like this:
This case is if your query is being done in Model Person
On your controller
$query = array(
'field' => 'Pessoas.*',
'conditions' => array(
'Pessoas.cpf' => $cpf,
),
);
$data = $this->Pessoa->find('all', $query);
debug($data);
Less simple subject:
If you are doing your query in the Project model, you need to create a Join in your query to use this condition.
In your controller:
$query = array(
'joins' => array(
array(
"table" => "pessoas_projetos",
"alias" => "PessoasProjetos",
"type" => "LEFT",
"conditions" => array(
"Projetos.id = PessoasProjetos.projeto_id"
)
),
),
'field' => '...',
'conditions' => array(
'PessoasProjetos.cpf' => $cpf
),
);
$data = $this->Projeto->find('all', $query);
debug($data);
In Joins you apply the relationship when you need to use conditions in the N: N
Remembering that these conditions are valid only if the Models are listed correctly.