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
-~----------~----~----~----~------~----~------~--~---

Reply via email to