That's a shame, as in this case ModelB is an alias, and so the
condition specified in the relationship to ModelA only applies to that
relationship.
In fact, in my particular case a Crop can have an Entry Classification
and an Attained Classification, which are sub-sets of the
Classification data set, so setting the condition in "ModelB" means
I'll have to create dummy EntryClassification and
AttainedClassification models that use the classifications table,
which I wanted to avoid for the sake of simplicity as these models
only exist as a relationship with a Crop.
I'll just have to use conditions on the find I suppose, or resort to
using separate models if I come across other problems.
Thanks for your response.
Regards,
Ian
On Nov 4, 11:33 am, "David C. Zentgraf" <dec...@gmail.com> wrote:
> Doing ModelA->ModelB->find() is the same thing as ModelB->find().
> It doesn't matter "through" which or how many models you go, it
> doesn't change the result.
> Which means, the conditions and associations you have defined in
> ModelB are being used here, so check those.
>
> On 4 Nov 2008, at 20:07, Ian M. Jones wrote:
>
>
>
> > Hi all,
>
> > I'm a little confused about something I'm seeing with belongsTo
> > conditions, and from searching the docs and this list I haven't been
> > able to find an answer. Maybe some kind soul can help clear my
> > confusion?
>
> > In my Crop model I have:
>
> > var $belongsTo = array(
> > 'EntryClassification' => array('className' => 'Classification',
> > 'foreignKey' => 'entry_classification_id',
> > 'conditions' => array('EntryClassification.entry' => 1),
> > 'fields' => '',
> > 'order' => ''
> > )
> > );
>
> > When I do an find operation on a Crop and let it pick up associated
> > models I see that the condition is used, a fragment from the where
> > clause displayed in the debugger would be like:
>
> > LEFT JOIN `classifications` AS `EntryClassification` ON
> > (`Crop`.`entry_classification_id` = `EntryClassification`.`id` AND
> > `EntryClassification`.`entry` = 1)
>
> > However, in my crops_controller I do for a select box:
>
> > $entryClassifications = $this->Crop->EntryClassification-
> >> find('list');
>
> > and it brings back all classifications, not just those that meet the
> > "EntryClassification = 1" condition.
>
> > This is confirmed in the debugger, I see:
>
> > SELECT `EntryClassification`.`id`, `EntryClassification`.`name` FROM
> > `classifications` AS `EntryClassification` WHERE 1 = 1
>
> > Why is that? Shouldn't a find through the Crop->EntryClassification
> > association use the condition?
>
> > Thanks for any help in clearing my confusion!
>
> > Ian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment