Skip to content

Commit

Permalink
Applying patch from 'farhadi' correcting regular expression when usin…
Browse files Browse the repository at this point in the history
…g magic findBy and fields that contain findBy in them. Fixes #6138

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8057 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Feb 25, 2009
1 parent 779b367 commit 2a139b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -225,10 +225,10 @@ function query() {

if (strpos(strtolower($args[0]), 'findby') === 0) {
$all = false;
$field = Inflector::underscore(preg_replace('/findBy/i', '', $args[0]));
$field = Inflector::underscore(preg_replace('/^findBy/i', '', $args[0]));
} else {
$all = true;
$field = Inflector::underscore(preg_replace('/findAllBy/i', '', $args[0]));
$field = Inflector::underscore(preg_replace('/^findAllBy/i', '', $args[0]));
}

$or = (strpos($field, '_or_') !== false);
Expand Down
7 changes: 7 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -3106,6 +3106,13 @@ function testMagicMethodQuerying() {
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);

$result = $this->testDb->query('findByFindBy', array('value'), $this->Model);
$expected = array('first', array(
'conditions' => array('TestModel.find_by' => 'value'),
'fields' => null, 'order' => null, 'recursive' => null
));
$this->assertEqual($result, $expected);

$result = $this->testDb->query('findAllByFieldName', array('value'), $this->Model);
$expected = array('all', array(
Expand Down

0 comments on commit 2a139b1

Please sign in to comment.