Applying patch from 'farhadi' correcting regular expression when using 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
This commit is contained in:
mark_story 2009-02-25 03:22:31 +00:00
parent 779b367d3b
commit 2a139b171c
2 changed files with 9 additions and 2 deletions

View file

@ -225,10 +225,10 @@ class DboSource extends DataSource {
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);

View file

@ -3106,6 +3106,13 @@ class DboSourceTest extends CakeTestCase {
'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(