diff --git a/src/Model/Behavior/ObfuscateBehavior.php b/src/Model/Behavior/ObfuscateBehavior.php index e7be2d4..9a3ba3a 100644 --- a/src/Model/Behavior/ObfuscateBehavior.php +++ b/src/Model/Behavior/ObfuscateBehavior.php @@ -91,8 +91,9 @@ public function beforeFind(Event $event, Query $query, ArrayObject $options, $pr } $query->traverseExpressions(function ($expression) { + $pk = $this->_table->primaryKey(); if (method_exists($expression, 'getField') - && $expression->getField() === $this->_table->primaryKey() + && in_array($expression->getField(), [$pk, $this->_table->aliasField($pk)]) ) { $expression->setValue($this->elucidate($expression->getValue())); } diff --git a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php index c1b96d0..d369350 100644 --- a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php @@ -99,6 +99,10 @@ public function testFindObfuscated() $results = $this->Articles->find('obfuscated')->where(['id' => 'S'])->toArray(); $this->assertEquals('S', $results[0]['id']); $this->assertCount(1, $results); + + $results = $this->Articles->find('obfuscated')->where(['Articles.id' => 'S'])->toArray(); + $this->assertEquals('S', $results[0]['id']); + $this->assertCount(1, $results); } public function testObfuscate()