I needed to check if a registry exists where the key is 4 fields.
I managed to resolve. Here's what I did.
I left this at the end of my model
public function beforeSave($options = array())
{
$any = $this->find('first', array(
'conditions' => array(
'Recibo.funcionario_id' => $this->data['Recibo']['funcionario_id'],
'Recibo.loja_id' => $this->data['Recibo']['loja_id'],
'Recibo.ano' => $this->data['Recibo']['ano'],
'Recibo.mes' => $this->data['Recibo']['mes'])));
if($any)
{
return false;
}else
{
return true;
}
}
and left a message on the controller to warn you that it was not included.
if ($this->Recibo->save($this->request->data)) {
$recibo_id=$this->Recibo->getInsertId();
foreach($this->request->data['ItenRecibo'] as $person)
{
//loop for each person added
$person['recibo_id']=$recibo_id;
$this->Recibo->ItenRecibo->create();
$this->Recibo->ItenRecibo->save($person);
}//end foreach
$this->Session->setFlash('Recibo salvo no BD');
$this->redirect(array('action' => 'index'));
}else
{
$this->Session->setFlash('Recibo já cadastrado para esse funcionário nesta data!');
}