Sunday, May 3, 2009

Re: Trying to Understand the Containable Behavior

On May 3, 10:55 am, jmcneese <jmcne...@gmail.com> wrote:
> it works if you associate your models correctly. in each of your
> models, associate them with the Alert model, like so:
>
> public $hasMany = array(
>   'AccountAlert' => array(
>     'className' => 'Alert',
>     'foreignKey' => 'entity_id',
>     'conditions' => array(
>       'AccountAlert.model' => 'Account'
>     )
>   )
> );
>
> do this with each model that has alerts, making sure to put the
> correct model name in the appropriate places.
>
> and then:
>
> $accountModel->contain(array(
>   'AccountAlert',
>   'Campaign' => array(
>     'CampaignAlert',
>     'Creative' => 'CreativeAlert'
> ));
> $accountModel->read(null, $account_id);

Hey, Joshua -

This is the first solution I've seen/found that looked like it had any
hope, but I'm not even a little bit familiar with the association
syntax you're using. I already have, in my Account model:

public $hasMany = array (
'Campaign',
'Alert' => array ( 'foreignKey' => 'entity_id' )
);

It looks like you're doing something slightly different, though, that
I've never seen. Can you point me to a resource that can help me
understand it better? Is there some additional functionality added by
defining a specific name for the Alert model join?

Thanks for your input. I'd love to be able to pull all alerts for any
account and its child items in one simple step. This looks like it
might get me there, but I'd like to understand more about what you're
suggesting.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: