On Jun 6, 12:46 pm, jameslagan <[EMAIL PROTECTED]> wrote: <snip> > If I try and use: > > $this->Badsession->recursive = 1; > $this->Badsession->findAll(); > > this runs 2 queries: > > SELECT `Badsession`.`id`, `Badsession`.`date`, > `Badsession`.`timestart`, `Badsession`.`timeend`, > `Badsession`.`venue_id` FROM `badsessions` AS `Badsession` WHERE 1 = 1 > > SELECT 'User`.`id`, `User`.`username`, `User`.`passwd`, > `User`.`last_visit`, `User`.`group_id`, `User`.`active`, > `User`.`created`, `User`.`modified` FROM `users` AS `User` JOIN > `badsessions_users` ON (`badsessions_users`.`badsession_id` = 2 AND > `badsessions_users`.`user_id` = `User`.`id`) WHERE 1 = 1 > > (NB: I should mention here I do not know why it states "WHERE 1 =1") It's the default constraint, so that you don't ever get WHERE ORDER BY (note what's missing). > > Okay so I want to make a condition now. Let's say "user_id = 1". i.e. > I want to find the row that corresponds to a user id of 1 and a > badsession id of 2 to see if they have already signed up for this > session. > > I do the following: > > $user_id = '1' > > $conditions = "user.id = ".$user_id; > > $this->Badsession->recursive = 1; > $this->Badsession->findAll($conditions); > > This, I believe, *should* work, however because findAll runs 2 queries > as stated above the first query returns an error: You can't include a constraint on a table that isn't in the query. Joins are only used for hasOne and belongsTo relationships. I think what I have written here: http://groups.google.com/group/cake-php/msg/fae9ec58501534e6 and here: http://groups.google.com/group/cake-php/browse_thread/thread/f23b1825050ad543/014092749592de70 or generally what you can find here: http://groups.google.com/group/cake-php/search?group=cake-php&q=filtering+habtm are relevant and will help. In short: 1) add a primary key to the join table 2) make it a model 3) do if (!$this->BadSession->SessionParticipant->hasAny(array(´User.id ´=> $userId, ´BadSession.id´=> $sessionId))) { // they have not already signed up} hth, AD --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" 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 -~----------~----~----~----~------~----~------~--~---
