Skip to content

Commit

Permalink
Fix cases using the aliased field, closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jadb committed Jan 19, 2016
1 parent dfc7dd1 commit 7000dc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Model/Behavior/ObfuscateBehavior.php
Expand Up @@ -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()));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php
Expand Up @@ -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()
Expand Down

0 comments on commit 7000dc2

Please sign in to comment.