sorry, I think I follow, maybe more specific objects will help, I have
Patient -> Diet Plans -> Diet Calendar Day
So Patient hasMany diet plans with each Diet Plan having many Diet
Calendar Days
I need to draw a screen of all patients and loop through 2 weeks of
the calendar, filling in details of each day for each patient, but I
need to be able to filter this at times by Patient last name,
sometimes by a field in Diet Calendar Days and other times in a field
in the Diet Plan. So they way I have it, I can't do Patient-
>find('all',array('condition' => 'DietPlan.active' => 1));
or
Patient->find('all',array('condition' => 'DietPlanDay.exception' =>
1));
Perhaps I have my db too normalized and I need to add a patient_id to
the Diet Calendar Day model as well.
On Aug 25, 1:00 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Aug 25, 7:13 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > I've scoured the group looking for a solution to this, can't make it
> > work with containable or with recursive = 2. I'm using latest
> > (nightly) 1.2
>
> > Model1 hasMany Model 2
> > Model2 belongsTo Model 1
> > Model2 hasMany Model 3
> > Model3 belongsTo Model2
>
> > So, I was really hoping to do a $this->Model3->find('all') and get the
> > data in a single sql query like
>
> > select Model3.xxxx, Model2.xxxx,Model1.xxx from Model3 left join Model
> > 2 left join Model1,
>
> You'll only get a single query with hasOne/belongsTo associations.
> I think you get the idea, so then I can sort and
>
> > filter using fields from any three models.
>
> > The best I can do is get Model 3 to join in the Model 2 table, then it
> > goes through the recursion to get Model 1 data. Note that I also
> > tried
>
> > this->Model1->Model2->Model3->find('all');
>
> Model3 (why use abstract names?) is an object. it's irrelevant how you
> get to it.
>
>
>
> > I tried this->Model3->contain(array('Model2'=>'Model1'));
> > I tried this->Model3->recursive = 2;
>
> > Is the only solution custom SQL in query() command?
>
> you need to temporarily or permanently bind hasOne associations in
> place of your hasManys. then do something like this:
>
> // Change model. Change->Revision->Node
> var $belongsTo = array(
> 'Revision',
> 'Node' => array('foreignKey' => false, 'conditions' =>
> array('Revision.node_id = Node.id'))
> );
>
> // Node model. Node<-Revision<-Change
> var $hasOne = array(
> 'Revision',
> 'Change' => array('foreignKey' => false, 'conditions' =>
> array('Change.revision_id = Revision.id'))
> );
>
> which you can use to get as many joins as you like.
>
> AD
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---