Saturday, April 25, 2009

Re: Model Association Not Creating Query Joins

On Apr 25, 9:55 am, James K <james.m.k...@gmail.com> wrote:
> Start from the AccountAlert model rather than the Alert model. Use
> contain as well.
>
> $alert_ids = $this->AccountAlert->find (
>         'all',
>         array (
>                 'contain' => array(),
>                 'conditions'    =>   array (
>                         'AccountAlert.account_id'  => $account_id
>                 ),
>                 'fields'                =>   array('alert_id'),
>         )
> );
>
> You should also use contain to restrict the number of models involved
> in each query. Containing an empty array (or an empty string, I can't
> remember) will tell your query to not join any other models.

Thanks, everyone. Has it always been like this? For some reason, I
would have sworn that in the past I've done something like this:

$this->AccountAlert->find (
'all',
array (
'conditions' => array (
'AccountAlert.active' => 1
),
'order' => 'Alert.priority'
)
);

Note the different models being used in the conditions and order
parameters. Has that never been possible?

Thanks again for the help. I'll definitely be digging into the
containable behavior.
--~--~---------~--~----~------------~-------~--~----~
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: