hmm, not sure... you could always write your own query or/and implement caching, depends on the load on you application.
On Jun 7, 10:42 pm, bmcelhany <[email protected]> wrote: > Ah, I didn't realize you could nest models within a single > "contain"...good to know! > > So, I gave that a shot and it works perfectly...just what I need! One > additional question: I notice that for each Item there is an > additional query performed to get that Item's Label information. I'm > not dealing with a huge amount of data so I'm not too concerned, but > it would be nice if I could maybe get the Label info via a join to the > Item, cutting the number of queries in half. > > In fact, most likely, any time I need an Item I'm going to need it's > associated Label as well. Any way I could modify the Item model and > tell it to always load it's associated Label? Or am I better off just > doing it via "contain" and leaving well enough alone? > > Thanks for your quick response! > > On Jun 7, 1:23 pm, vekija <[email protected]> wrote: > > > > > It should work with Containable behavior. > > > for example > > > $categories = $this->Category->find('all', array('contain' => > > array('Item' => array('Label')))); > > > should return an array like: > > > Category 1 > > Item 1 > > Label 1 > > Item 2 > > Label 2 > > Category 2 > > Item 3 > > Label 3 > > > On Jun 7, 10:17 pm, bmcelhany <[email protected]> wrote: > > > > Hi all, > > > > I've been working on this for a while and searching for a solution, > > > but can't seem to get it working correctly. Let's say I have Category, > > > Label, and Item models with the following associations: > > > > Category hasMany Items > > > Item belongsTo Category > > > Label hasMany Items > > > Item belongsTo Label > > > > So, Categories and Labels are completely unrelated, but the Item > > > belongs to both of them. Now, in my Category view (and Category > > > controller) I want to display the Cateogry info (obviously) and a list > > > of all of that Category's Items. So far so good. However, what I'd > > > also like is, for each Item that is listed, to display that Item's > > > associated Label. Something like: > > > > Category 1 > > > Item 1 (Label for Item 1) > > > Item 2 (Label for Item 2) > > > Category 2 > > > Item 3 (Label for Item 3) > > > > I've tried different combinations of recursion (on all three models) > > > and I've tried using the containable behavior but I can't seem to get > > > the Label data to be included. The label data appears fine when I'm > > > working with the Item views and controller, but when I'm up one level > > > higher (in the context of a Category) they aren't attached. > > > > Any thoughts on this? Thanks! 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
