Hello Rob, I am not sure, but I think Polymorphic Behavior might help you. It is on the bakery. You can bind that one model dynamically to other models by specifying it category (called class).
I am not sure but I do not see why it should not work with containable. I'd frist try to use "complex find conditions" + Polymorphic Behavior - debug = 2 in core.php and see if the query fetches much unnecessary data. You could strip that down by specifying which fields should be returned. Hope that helps/works. Regards Jonas p.s. you could as well fetch alerts per model (3 calls) and then array_combine or Set::combine or so the results. On May 3, 1:25 am, Rob Wilkerson <[email protected]> wrote: > I'm trying to do something that I think is reasonably complex (and > maybe outside of what the behavior was intended to do) with the > Containable behavior and, although I seem to be dancing all around it, > I can't get it quite right. I'm hoping someone here can either tell me > I'm trying to do something that can't be done or help me get it right. > > I have models for Account, Campaign and Creative. An Account hasMany > Campaign and a Campaign hasMany Creative. I have an alert model that > belongs to all of these via a "generic" entity_id foreign key. This > allows me to set an alert for any of these models and retrieve them > accordingly without having to create a bunch of separate models. So > here's the thing: > > What I'd like to do is, for a given Account, retrieve all of the > alerts that are relevant to that Account - including those related to > its Campaigns and the Creatives related to the Campaigns. I think (or > maybe "hope" is more appropriate) that's possible using Containable. > Ideally, I'd like to get back an array containing the Alert object and > the object to which it belongs, but no empty objects. In other words, > don't return an Account object if the Alert is attached to a Campaign. > > I've tried separately "containing" those models as well as containing > them in a nested manner. Here is the current code for the nested > containment being called from the Account model: > > $alerts = $this->Alert->find ( > 'all', > array ( > 'contain' => array ( > 'Account' => array ( > 'conditions' => array ( > 'Account.id' => $account_id ), > 'Campaign' => array ( > 'conditions' => array > ( 'Campaign.account_id' => $account_id ) > ) > ) > ) > ) > ); > > Any thoughts would be much appreciated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
