From 0c2b92a650662e845478fb2d692e98401b3f2812 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 29 Mar 2007 01:45:13 +0000 Subject: [PATCH] Fixing NOT operations in query conditions in DboSource (Ticket #2307) git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4704 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 3 +++ .../cases/libs/model/datasources/dbo_source.test.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 5e2e73b5a..0e2d8150e 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1424,6 +1424,9 @@ class DboSource extends DataSource { $join = ' ' . strtoupper($key) . ' '; $value = $this->conditionKeysToString($value, $quoteValues); if (strpos($join, 'NOT') !== false) { + if (up(trim($key)) == 'NOT') { + $key = 'AND ' . $key; + } $out[] = 'NOT (' . join(') ' . strtoupper($key) . ' (', $value) . ')'; } else { $out[] = '(' . join(') ' . strtoupper($key) . ' (', $value) . ')'; diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 7fbf036e4..bb5574a02 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -943,6 +943,15 @@ class DboSourceTest extends UnitTestCase { $result = $this->db->conditions(array('(Usergroup.permissions) & 4' => 4)); $this->assertPattern('/^\s*WHERE\s+\(`Usergroup`\.`permissions`\)\s+& 4\s+=\s+4\s*$/', $result); + + //$result = $this->db->conditions(array('((Usergroup.permissions) & 4)' => 4)); + //$this->assertPattern('/^\s*WHERE\s+\(\(`Usergroup`\.`permissions`\)\s+& 4\)\s+=\s+4\s*$/', $result); + + $result = $this->db->conditions(array( + 'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)), + 'Enrollment.yearcompleted' => '> 0') + ); + $this->assertPattern('/^\s*WHERE\s+NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(`level_of_education_id` IN \(912, 999\)\s*\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+0\s*$/', $result); } function testFieldParsing() {