you have to do some inner joins... like

$this->ApprovalRequisitions->find('all',array(
    'joins' => array(
        array(
            'table' => 'approval_requisitions_professionals',
            'alias' => 'ApprovalRequisitionsProfessional',
            'type' => 'inner',
            'conditions' => array
('ApprovalRequisitionsProfessional.approval_requisition_id =
ApprovalRequisition.id')
        ),
        array(
            'table' => 'professionals',
            'alias' => 'Professional',
            'type'=>'inner',
            'conditions'=>array('Professional.id =
ApprovalRequisitionsProfessional.professional_id')
        )
    ),
    'conditions' => array('Professional.id' => $your_special_id)
)

but be a bit careful with that: you will never find any
ApprovalRequisitions which are not related to a certain Professional
even if you leave the conditions-array blank. (see how inner joins are
working, if you want to know why)

On Mar 12, 7:57 pm, Antônio Marco <[email protected]> wrote:
> Hi!
>
> I have an app with a few models; Claimant, Professional and
> ApprovalRequisition among them.
>
> Some of most important associations are:
>
> - Claimant hasMany ApprovalRequisitions;
> - Professional hasAndBelongsToMany ApprovalRequisition; and,
> - ApprovalRequisition hasAndBelongsToMany Professional.
>
> Starting from the ApprovalRequisition model, I need to retrieve all
> Claimant's ApprovalRequisitions. Until now, no problem.
>
> I'm using the code:
>
> $claimant_approval_requisitions = $this->ApprovalRequisition->find(
>     'all',
>     array(
>         'conditions' => array(
>             'ApprovalRequisition.claimant_id' => $claimant_id
>         )
>     )
> );
>
> debug($claimant_approval_requisitions) shows:
>
> Array(
>     [0] => Array(
>         [ApprovalRequisition] => Array(
>             [id] => 1
>             [created] => 2009-03-11 11:27:35
>             [modified] => 2009-03-11 11:27:35
>             [claimant_id] => 1
>         )
>
>         [Claimant] => Array(
>             [id] => 1
>             [created] => 2009-02-17 16:55:30
>             [modified] => 2009-02-17 16:55:30
>         )
>
>         [Professional] => Array(
>             [0] => Array(
>                 [id] => 2
>                 [created] => 2009-03-12 09:37:38
>                 [modified] => 2009-03-12 09:37:38
>                 [ApprovalRequisitionsProfessional] => Array(
>                     [id] => 3
>                     [created] => 2009-03-12 09:40:46
>                     [modified] => 2009-03-12 09:40:46
>                     [requisition_id] => 1
>                     [professional_id] => 2
>                 )
>             )
>
>             [1] => Array(
>                 [id] => 1
>                 [created] => 2009-02-17 16:55:30
>                 [modified] => 2009-03-04 10:08:37
>                 [ApprovalRequisitionsProfessional] => Array(
>                     [id] => 1
>                     [created] => 2009-03-11 11:27:35
>                     [modified] => 2009-03-11 11:27:35
>                     [requisition_id] => 1
>                     [professional_id] => 1
>                 )
>             )
>         )
>     )
>
>     [1] => Array(
>         [ApprovalRequisition] => Array(
>             [id] => 2
>             [created] => 2009-03-12 11:26:01
>             [modified] => 2009-03-12 11:26:01
>             [claimant_id] => 1
>         )
>
>         [Claimant] => Array(
>             [id] => 1
>             [created] => 2009-02-17 16:55:30
>             [modified] => 2009-02-17 16:55:30
>         )
>
>         [Professional] => Array(
>             [0] => Array(
>                 [id] => 1
>                 [created] => 2009-02-17 16:55:30
>                 [modified] => 2009-03-04 10:08:37
>                 [ApprovalRequisitionsProfessional] => Array(
>                     [id] => 4
>                     [created] => 2009-03-12 11:26:01
>                     [modified] => 2009-03-12 11:26:01
>                     [requisition_id] => 2
>                     [professional_id] => 1
>                 )
>             )
>         )
>     )
> )
>
> My problem is retrieving all Professional's ApprovalRequisitions...
>
> Basically, I wish to retrieve *ONLY* ApprovalRequisitions that belongs
> to a given Professional. Simple like that.
>
> Yes, I know that would be much more simple starting from the
> Professional model to obtain all yours ApprovalRequisitions.
>
> Can someone help me?
>
> Thanks a lot.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to