Thanks for that. Adding in 'DISTINCT' worked... but there is no duplication in the database (id is a unique field).
I'm now doing: $userlist = $this->User->find('all', array('conditions' => array('group_id' => 1), 'fields' => array('DISTINCT User.id'))); and that's working fine. However, when I had: $userlist = $this->User->find('all', array('conditions' => array('group_id' => 1), 'fields' => array('User.id'))); and then: $userlist = $this->User->query("SELECT id FROM `users` WHERE group_id = 1"); I got different results - the 'find' was bringing back 3 copies of one record. Anyway, it's working now - thanks for the help. I'd be interested to hear if anyone can tell me what's wrong with the first version, though! On 7 July, 10:43, grigri <j...@hendersonwebdesign.com> wrote: > That's very odd... with that query you shouldn't get any duplicates. > > Are you absolutely sure they're duplicates, not just identical rows in > the database? Do they have the same ID? > > Try unbinding the associations - if you get the correct results then > add-in the associations one by one. > > Otherwise, try setting the "fields" to "DISTINCT User.id, > User.whatever, ...". Or set the 'group' key to "User.id" - either > should remove the duplicates. > > hth > grigri > > On Jul 5, 5:51 pm, WhyNotSmile <sharongilmor...@gmail.com> wrote: > > > Thanks grigri, that's a handy tip. > > > I get the following now (I left out the list of fieldnames, because > > there are loads of them): > > > SELECT {list of fieldnames} > > FROM `users` AS `User` > > LEFT JOIN `groups` AS `Group` ON (`User`.`group_id` = `Group`.`id`) > > LEFT JOIN `user_types` AS `UserType` ON (`User`.`user_type_id` = > > `UserType`.`id`) > > LEFT JOIN `user_statuses` AS `UserStatus` ON (`User`.`user_status_id` > > = `UserStatus`.`id`) > > LEFT JOIN `user_profiles` AS `UserProfile` ON (`UserProfile`.`user_id` > > = `User`.`id`) > > LEFT JOIN `user_prefs` AS `UserPrefs` ON (`UserPrefs`.`user_id` = > > `User`.`id`) > > LEFT JOIN `user_friends` AS `UserFriend` ON (`UserFriend`.`user_id` = > > `User`.`id`) > > LEFT JOIN `access` AS `Access` ON (`Access`.`user_id` = `User`.`id`) > > WHERE `User`.`group_id` = 1 LIMIT 34 > > > It looks ok (though I'm no expert in mySQL), but when I ran that as > > just a SQL query, i.e. $results = $this->User->query(); I'm still > > getting the duplicated results. > > > Very confused now :s > > > On 5 July, 16:27, grigri <j...@hendersonwebdesign.com> wrote: > > > > I've never tried setting the debug value from the controller; it's > > > possible that it needs to be set up beforehand. > > > > I do this on some sites like this, in app/config/bootstrap.php: > > > > if (isset($_GET['setthegorramdebugmode'])) { > > > Configure::write('debug', $_GET['setthegorramdebugmode']); > > > > } > > > > (Obviously, use a different key than 'setthegorramdebugmode' - use > > > whatever you like). > > > > Then just append '?setthegorramdebugmode=2' on to the end of the URL > > > in the browser, and it will enable debug mode, just for you. > > > > I don't recommend keeping this in place on live sites, however. It > > > _should_ be safe, but you never know... > > > > hth > > > grigri > > > > On Jul 5, 4:12 pm, WhyNotSmile <sharongilmor...@gmail.com> wrote: > > > > > Thanks. I did that in the controller (I don't want to change it for > > > > everything, because it's a live site), but I get: > > > > > (default) 0 query took ms Nr Query Error Affected Num. > > > > rows Took (ms) > > > > > at the bottom. Am I doing something wrong? > > > > > Thanks, > > > > Sharon > > > > > Configure::write('debug', 2); > > > > > On 5 July, 16:07, grigri <j...@hendersonwebdesign.com> wrote: > > > > > > Open app/config/core.php, change the line (near the top) to > > > > > `Configure::write('debug', 2);` [from whatever it was]. > > > > > > Now when you access the page, you'll see the SQL log at the bottom. > > > > > > hth > > > > > grigri > > > > > > On Jul 5, 3:58 pm, WhyNotSmile <sharongilmor...@gmail.com> wrote: > > > > > > > I'm not sure how to get that... I don't have access to the SQL log, > > > > > > as > > > > > > far as I know. Can you suggest where I might look? > > > > > > > Thanks. > > > > > > > On 5 July, 15:35, grigri <j...@hendersonwebdesign.com> wrote: > > > > > > > > What is the corresponding query in the SQL log? > > > > > > > > On Jul 5, 3:29 pm, WhyNotSmile <sharongilmor...@gmail.com> wrote: > > > > > > > > > I'm doing a paginate query, and it's returning the same row 4 > > > > > > > > times. > > > > > > > > The other results in the set are all present and each is shown > > > > > > > > once. > > > > > > > > > Has anyone come across this before? > > > > > > > > > My Users controller code is as follows: > > > > > > > > > $this->paginate = array( > > > > > > > > 'limit' => $limit, > > > > > > > > 'conditions' => $find > > > > > > > > ); > > > > > > > > > $userlist = $this->paginate('User'); > > > > > > > > > and at the point of calling this code, $limit is 34 and debug > > > > > > > > on $find > > > > > > > > gives: > > > > > > > > > Array > > > > > > > > ( > > > > > > > > [and] => Array > > > > > > > > ( > > > > > > > > [User.synagogue_id] => 1 > > > > > > > > ) > > > > > > > > > ) > > > > > > > > > Any ideas what I'm doing wrong? The record is definitely not > > > > > > > > duplicated in the DB. > > > > > > > > > Thanks! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en