On May 30, 12:35 pm, uolax <[EMAIL PROTECTED]> wrote:
> Thanks so much for any time with this:
>
> Forest->hasMany->Trees
> trees->belongsTo->Forest
>
> I want to:
> find the forests that only have trees that are brown, (each tree can
> only belong to one forest)
> list the other trees in those respective forest,
> and don't list forests that have no brown trees all from the
> forests_controller.
If I understand you properly, you want to list trees from forests that
have ONLY brown trees - no trees of any other color? If so, perhaps
you could first find all forests that have at least one tree that is
not brown, then just find the trees in all other forests. In ugly
pseudo-cake-code:
//first find all forests with at least one non-brown tree
$discardForestIDs = $this->forest->findAll('trees.treecolor !=
'brown', 'forest.id')
//then arrange $discardForestIDs into usable SQL format
$this->forest->findAll('forest.id NOT IN ($discardForestIDs))
or something to that effect. I may not be referring to the models in
quite the way that Cake expects, but I hope you get the idea.
> I've unsuccesfully tried Bind/Unbind in the Forest Controller, setting
> the conditions -> 'trees.treecolor = brown' while still using hasMany.
> However, this still returns ALL forests but hides the associated data
> that doesn't meet the condition.
Is this because all forests contain at least one brown tree?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---