From 990d0a962f3897f41ef3eae95be855b9ffbd66df Mon Sep 17 00:00:00 2001 From: Cory Thompson Date: Tue, 24 Jan 2017 19:33:12 +1100 Subject: [PATCH] Allow database JSON operations in conditions --- lib/Cake/Model/Datasource/DboSource.php | 3 ++- lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 0baabe0da..2f5489778 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2897,7 +2897,8 @@ class DboSource extends DataSource { $isKey = ( strpos($key, '(') !== false || strpos($key, ')') !== false || - strpos($key, '|') !== false + strpos($key, '|') !== false || + strpos($key, '->') !== false ); $key = $isKey ? $this->_quoteFields($key) : $this->name($key); } diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index fa247d382..0ce8a937a 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -244,15 +244,16 @@ class DboSourceTest extends CakeTestCase { } /** - * test that PostgreSQL json operators can be used. + * test that SQL JSON operators can be used. * * @return void */ public function testColumnHyphenOperator() { $result = $this->testDb->conditions(array('Foo.bar->>\'fieldName\'' => 42)); - echo "Result is: "; - echo $result; - $this->assertEquals(' WHERE `Foo`.`bar`->>\'fieldName\' = 42', $result, 'pgsql json operator failed'); + $this->assertEquals(' WHERE `Foo`.`bar`->>\'fieldName\' = 42', $result, 'SQL JSON operator failed'); + + $result = $this->testDb->conditions(array('Foo.bar->\'fieldName\'' => 42)); + $this->assertEquals(' WHERE `Foo`.`bar`->\'fieldName\' = 42', $result, 'SQL JSON operator failed'); } /**