Well,
Containable will not do what you want in this case.
Containable will not limit your primary result-set by conditions on
some associated model.

Logically it might be said to flow like this:
Your query will find all Users since you have no condition to limit
the users.
Each User will also "contain" it's Student if it has one.
Each such related Student will contain it's Submissions if it has any
and student_id is null.

What you want is a join. One that returns only if there is no record
to join to in the submissions table.
You can do joins a bit Cake-like. Pass 'joins' and an array of
parameters to find. It is not well documented in the manual but Nate
wrote a great article for the bakery about it:
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find

You don't have to build anything like what he suggests but at least it
contains some examples of using the joins key.

A quick googling gave me this page detailing some variations of joins
that might help you figure out which type of join you need.
http://www.wellho.net/solutions/mysql-mysql-joins-using-left-join-and-right-join-to-find-orphan-rows.html


/Martin




On Dec 3, 1:53 am, Bryan Paddock <[email protected]> wrote:
> Hmm... nobody have any ideas?
>
> On Tue, Nov 24, 2009 at 4:05 PM, Bryan Paddock <[email protected]>wrote:
>
>
>
> > Hey all,
>
> > I have this relationship in question:
>
> > User -> hasOne Student -> hasMany Submission
>
> > I'm a bit stumped on how I can fetch all the users who do not have any
> > submissions linked to their name.
>
> > I've tried:
>
> >         $list = $this->User->find('all', array(
> >           'contain' => array(
> >             'Student' => array(
> >               'Submission' => array(
> >                 'conditions' => array(
> >                   'Submission.student_id' => null
> >                 )
> >               ),
> >             )
> >           )
> >         ));
>
> > I have the actAs in the model so the containable behaviour is functioning -
> > there is just a problem with my specific query.
>
> > Any ideas?
>
> > thanks!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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