Paul, sorry for the late reply, I wasn't notified of your response. Your trick worked like a charm, thanks man, I've been scratching my head over this for ages. So it's not just me going crazy then, I am having problems in a few places getting ORM to return my results, as I am newish to Cake I kept thinking I must be doing something wrong, its nice to know I'm not a complete idiot.
Thanks. On Feb 11, 3:41 am, WebbedIT <[email protected]> wrote: > Now people keep telling me that I am wrong here, but I have always had > problems with deep belongsTo associations not being fetched with > recursive alone. > > In your instance LocalInfo belongsTo Subcat which belongsTo Cat which > belongsTo Location and your find recursive stops after the first > belongsTo only finding LocalInfo and Subcat. > > There are a few things you can do. > > 1. Force a join from LocalInfo to Cat by doing the following in the > controller before the find > > $this->LocalInfo->bindModel(array('belongsTo'=>array( > 'Cat'=>array( > 'foreignKey'=>false, > 'type'=>'INNER', > 'conditions'=>array('Subcat.cat_id = Cat.id') > ) > )), true); > > The last condition defaults to true so you dont actually need to pass > it, but if your paginating results needs to be set to true to make the > bind persistent otherwise the bind only exists for the first find that > follows it. > > If you need also need data from Location you would need to bind that > too as follows: > > $this->LocalInfo->bindModel(array('belongsTo'=>array( > 'Cat'=>array( > 'foreignKey'=>false, > 'type'=>'INNER', > 'conditions'=>array('Subcat.cat_id = Cat.id') > ), > 'Location'=>array( > 'foreignKey'=>false, > 'type'=>'INNER', > 'conditions'=>array('Cat.location_id = Location.id') > ) > )), true); > > 2. The 2nd option is to use containable, which I use all the time and > is great as long as you're not needing to place any conditions on the > deep tables, in which case you must do the above. > > http://book.cakephp.org/view/474/Containable > > HTH > > Paul. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
