First of all, at least to me, you will either have to use Polymorphic
Behavior OR you cannot use "foreignKey" but need to use multiple FKs
per model.
Following example would NOT use polymorphic (but some FKs being NULL
instead) - it uses one FK per model that is bound to Alert.
Account HasMany Campain, Campain BelongsTo Account (account_id in
campains table)
Campain HasMany Creative, Creative BelongsTo Campain (campain_id in
creatives table)
Account HasMany Alert, Alert BelongsTo Account (account_id in alerts
table)
Campain HansMany Alert, Alert BelongsTo Campain (campain_id in alerts
table)
Creative HansMany Alert, Alert BelongsTo Creative (creative_id in
alerts table)
Make sure those are setup correcty. Setup those in your DB and use
"cake bake" to create the models.
If you are working in an already finished app, just separate the
problem into a new app and bake that app.
I am still not sure if this works but I would try something like this:
<?php
$allAlerts = $this->Account->find(
'all',
array(
'fields' => array(
'Alert.title',
'Alert.body',
'Alert.created',
),
'conditions' => array(
// This selects a given Account - if you want
multiple try
'Account.id' => array(1, 2, 3), should result into IN(1,2,3)
'Account.id' => $givenAccountid,
// This does the joins
'Account.id' => 'Campain.account_id'
'Campain.id' => 'Creative.comapin_id'
// This selects all of the possible alerts
'OR' => array(
'Alert.account_id' = 'Account.id'
'Alert.campain_id' = 'Campain.id'
'Alert.creative_id' = 'Creative.id'
)
)
'order' => 'Alert.created DESC'
)
);
?>
Set debug = 2 in core.php and see if the queries do the right thing.
If that, I am again not sure but maybe you can switch to contains this
way:
<?php
$allAlerts = $this->Account->find(
'all',
array(
'fields' => array(
'Alert.title',
'Alert.body',
'Alert.created',
),
// This does the joins
'contain' => array(
'Campain' => array(
'Creative'
)
),
'conditions' => array(
// This selects a given Account - if you want
multiple try
'Account.id' => array(1, 2, 3), should result into IN(1,2,3)
'Account.id' => $givenAccountid,
// This selects all of the possible alerts
'OR' => array(
'Alert.account_id' = 'Account.id'
'Alert.campain_id' = 'Campain.id'
'Alert.creative_id' = 'Creative.id'
)
),
'order' => 'Alert.created DESC'
)
);
?>
I hope that helps.
Jonas
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---