From 2a139b171c06195fed346178d481b5e80bac63ac Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 25 Feb 2009 03:22:31 +0000 Subject: [PATCH] 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 --- cake/libs/model/datasources/dbo_source.php | 4 ++-- .../tests/cases/libs/model/datasources/dbo_source.test.php | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 6b2e5cfae..541320cce 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -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); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index fc3cef0df..a1e800381 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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(