0

I have User HABTM through Solicitation that is SocilitationUser model.

When I do debug($this->User->find('all')); i get this array

array(
(int) 0 => array(
    'User' => array(
        'password' => '*****',
        'id' => '1',
        'username' => 'advogado',
        'email' => 'igor.cesar@sotreq.com.br',
        'nivel' => 'advogado',
        'nome' => 'Bruno',
        'superior' => '0',
        'sector_id' => '2',
        'aprovador' => '1'
    ),
    'SolicitationUser' => array(
        (int) 0 => array(
            'id' => '9',
            'solicitation_id' => '72',
            'user_id' => '1',
            'funcao' => ''Advogado''
        ),
        (int) 1 => array(
            'id' => '11',
            'solicitation_id' => '73',
            'user_id' => '1',
            'funcao' => ''Advogado''
        ),
           ...... 

How can i get All Solicitations where active = 1 and user.id = 1 ??

Igor Martins
  • 2,015
  • 7
  • 36
  • 57

2 Answers2

0

If the User has a field active (I can't see the field active in both User and SolicitationUser based on the result you posted)

  $conditions = "User.active=1 AND SolicitationUser.user_id=1"; //if the active belongs to SolicitationUser model just modify it to SolicitationUser.active
  $solicitations = $this->Solicitation->find('all', compact('conditions'));
decodingpanda
  • 594
  • 9
  • 18
0

I find it effective to just go through the HABTM model:

$this->SolicitationUser->find('all',array(
    'conditions'=>array('SolicitationUser.user_id'=>1,'Solicitation.active'=>1)
);
Nick Zinger
  • 1,174
  • 1
  • 12
  • 28