*laf*  This is totally awesome - I never would have thought of this,
but it looks like it does work.

Looking at the SQL, it looks like the initial query is unchanged:
SELECT `Term`.`id`, `Term`.`year`, `Term`.`quartername` FROM `terms`
AS `Term` WHERE 1 = 1 ORDER BY `year` DESC

But the next query has that condition tacked onto it:

SELECT `Course`.`id`, `Course`.`term_id` /* SNIP */ FROM `courses` AS
`Course`
    WHERE `Course`.`id` =1
                    AND
                 `Course`.`term_id` IN (3, 2, 1)

I'm guessing that it's best to immediately remove the condition after
doing this.

Thanks!
--Mike

On Jun 30, 11:51 pm, majna <[EMAIL PROTECTED]> wrote:
> First question: maybe with Containable behaviour?
>
> $this->Term->contain('Course' => array(
>     'conditions'=>array( 'Course.id' => 1),
>     'order' => 'year DESC',)
> );
>
> Damn, You can even be dirty  $this->Term->hasMany['Course']
> ['conditions'] =" Course.id =1;"    :)
>
> On Jul 1, 6:49 am, Grant Cox <[EMAIL PROTECTED]> wrote:
>
>
>
> > The documentation you are referring to is misleading - a join is only
> > used across a belongsTo association (and hasOne), never for hasMany.
>
> > Basically, you can't have query conditions across a hasMany
> > association.  You will have to either query the other way (as you saw,
> > the Course belongsTo Term, so you can put Term conditions in the
> > Course query), or do the filtering in PHP after retrieving all data.
> > The Containable behaviour will not help with this - it really just
> > does some tricky bind / unbind and sets the appropriate recursive for
> > the  query, it won't help with conditions.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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