HABTM are never done with a JOIN, so you can't use conditions across
the query.  You can only do this with belongsTo, so in your example
you would be able to use Service fields in the conditions, but not
Event, Group or User.

The options that I see you have.

1.  Create models for the join tables (ServiceUser, ServiceGroup,
ServiceEvent) - so you will have Service belongsTo ServiceUser, and
User belongsTo ServiceUser (so three models, each belongsTo the middle
one, rather than HABTM).  Might be a pain, as you then have to manage
the connections yourself.  But due to the belongsTo, your conditions
will work on these join models.

2.  Write custom SQL.  You'll either have to JOIN to the join tables
(so basically #1 but without Cake models, just writing the SQL
yourself), or you could use subselects.

3.  Collate in PHP, rather than SQL.  If you changed your query to
(using the new 1.2 syntax):

$user_options = array(
        'conditions' => array('User.id'=>$user_ids),
        'contain' => 'Serviceaccount'
)
$user_serviceaccounts_result = $this->User->find('all',
$user_options);
$user_serviceaccounts = Set::extract($user_serviceaccounts,
'{n}.Serviceaccount');

... ditto for Groups and Events

then you could collate these arrays into a total.



On Jun 3, 6:09 pm, pr1001 <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> findAll() seems to ignore the recursive option, no matter how I set
> it. I'm running a HEAD version of 1.2 download sometime in mid April
> to early May (sorry for the lack of clarity). Maybe I'm confused, but
> I believe that, with my model Serviceaccount in a HABTM relationship
> with the User model, I go do something like 
> $this->Serviceaccount->findAll(array('User.id' => $some_id)) when 
> $this->Serviceaccount-
> >recursive is set to 1 or 2. Unfortunately, the generated SQL doesn't
>
> do the joins to necessary to allow such a query.
>
> Code here:http://bin.cakephp.org/view/956503259
>
> Any ideas? Thanks!
>
> Peter Robinett
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to