I needed to check if there was a record where the key is 4 fields.
I got it sorted out. Here’s what I did.
I left it 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 that it did not include.
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!');
}