In cases like what you are looking at it tends to work a bit better if
you rather do the find on the model you want to filter.
Something like:
$alert_ids = $this->Alert->AccountAlert->find (
'all',
array (
'conditions' => array (
'AccountAlert.account_id' => $account_id
),
'fields' => array('Alert.id'),
)
);
That might work (Sorry, sitting at university, can't test).
Otherwise you can try the containable behaviour, that should be able
to do what you wish.
On Apr 24, 2:45 am, Rob Wilkerson <[email protected]> wrote:
> I have an Alert model, an Account model and an AccountAlert model:
>
> Alert hasMany AccountAlert
> Account hasMany AccountAlert
> AccountAlert belongsTo ( Alert, Account )
>
> AccountAlert has several other defining fields, so it has its own
> primary key in the database as well as being its own model. IOW, it's
> more than a simple linking table. It has foreign keys to the alerts
> and accounts tables (alert_id and account_id, respectively).
>
> From AccountModel, I'm trying to retrieve all of the Alerts for a
> given Account. If I try a simple find:
>
> $this->Alert->find ( 'all' )
>
> I get each Alert and each AccountAlert that has that alert. If,
> however, I try to restrict by the account_id then I get an unknown
> column error:
>
> $alert_ids = $this->Alert->find (
> 'all',
> array (
> 'conditions' => array (
> 'AccountAlert.account_id' => $account_id
> ),
> 'fields' => array('id'),
> )
> );
>
> Looking at the debug SQL, no join is being created. Since the model
> associations are intact (I assume this is the case since the simple
> find() returns data for both models), should CakePHP be building the
> join automagically and, therefore, understanding the
> AccountAlert.account_id syntax in my condition?
>
> Even being relatively new to CakePHP, it still seems like I should
> have run into this before, but I can't remember having seen this. Any
> push in the right direction 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
-~----------~----~----~----~------~----~------~--~---