On Fri, Feb 20, 2009 at 10:42 AM, Al <[email protected]> wrote:
>
> Hello, can someone tell me if this is possible? I have the following
> Model association:
>
> PhdUser hasOne PhdApplication
> PhdApplication hasMany PhdCollege
>
> So a user inputs multiple colleges for their application, and I want
> to query for only the most recent college (dateLeft).
>
> I've just started understanding and using the containable behavior and
> was trying along these lines:
>
> $query = $this->PhdUser->find('all', array(
>                                                                
> 'contain'=>array(
>                                                                
> 'PhdCollege'=>array('dateLeft = max(dateLeft)'),
>                                                                
> 'PhdApplication'=>array('userID = "6240"'),
>                                                                'PhdTest'
>                                                                ),
>

I'm not sure about the other thing but, if you want just a single
User, do find('first', ...). Remove the array('userID = "6240"') and
add a 'conditions' array to the same level as 'contain' with 'id' =>
$user_id

$query = $this->PhdUser->find(
        'first',
        array(
                'conditions' => array(
                        'PhdUser.id' => $user_id
                ),
                'contain'=>array(
                        'PhdCollege' => array(
                                // whatever this turns out to be
                        ),
                        'PhdApplication',
                        'PhdTest'
                )
        )
);

--~--~---------~--~----~------------~-------~--~----~
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