to a hasOne - should that make a difference? Model3 was joining with
the wrong table otherwise...)! The only minor detail is that I need
the containment behavior, and then it doesn't work (even when I
include all the keys I'm dealing with...). Is there any way around
this?
Thanks again for the help (I would have never gotten that one myself)!
Dave.
On Mar 20, 3:40 pm, jcorrea <javier.cor...@gmail.com> wrote:
> I do this a lot (not so much in Model::belongsTo but in bindModel
> (...)):
> class Model1 extends AppModel {
> ...
> var $belongsTo = array(
> 'Model2',
> 'Model3' => array('foreignKey' => false, 'conditions' =>
> 'Model2.model3_id = Model3.id')
> );
> ...
>
> }
>
> Then in the find you can do something like:
> Model1->find('all', array('conditions' => array('Model3.field' =>
> $value)))
>
> On Mar 19, 5:05 pm, dave08 <dava...@gmail.com> wrote:
>
> > I think I finally understand. When the associations are properly done,
> > one can use the contains behaviour or recursive option in the find()
> > function. The thing I still have a problem with, is that I need to
> > filter all the results with a condition on model3. I tried using
> > condition in the find function on model1, but it doesn't recognize the
> > field in model3. I also tried a condition on the contains function,
> > but even that only eliminates the records returned from model3 - not
> > all the other ones...
>
> > Any help would be greatly appreciated (I hope the problem was clearly
> > stated?),
>
> > Dave.
>
> > On Mar 19, 9:34 am, dave08 <dava...@gmail.com> wrote:
>
> > > Hello!
>
> > > I have one model that I declared with a hasOne association to model2,
> > > and in model2, I need a belongTo association to a third model (a
> > > lookup table). This whole association should be accessible with a find
> > > () from the first model - is this possible in cakePHP, or do I have to
> > > make two (or a custom) query to accomplish this?
>
> > > Just to make the question clearer here's the structure:
>
> > > Model1 (This model is where I'm calling the find...)
> > > -Id
>
> > > Model2
> > > -model1_id
> > > -model3_id
>
> > > Model3
> > > -Id
>
> > > Thanks in advance for any help!
--~--~---------~--~----~------------~-------~--~----~
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