diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 3d3c3667d..ee7501bce 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2103,6 +2103,11 @@ class DboSource extends DataSource { } } + $virtual = false; + if (!empty($model->virtualFields[$key])) { + $key = $model->virtualFields[$key]; + $virtual = true; + } $type = (is_object($model) ? $model->getColumnType($key) : null); @@ -2117,7 +2122,7 @@ class DboSource extends DataSource { $value = $this->value($value, $type); - if ($key !== '?') { + if (!$virtual && $key !== '?') { $isKey = (strpos($key, '(') !== false || strpos($key, ')') !== false); $key = $isKey ? $this->__quoteFields($key) : $this->name($key); } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 490b1b97e..255ecbdba 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -1247,7 +1247,6 @@ class ControllerTest extends CakeTestCase { function testPaginateOrderVirtualField() { $Controller =& new Controller(); $Controller->uses = array('ControllerPost', 'ControllerComment'); - $Controller->passedArgs[] = '1'; $Controller->params['url'] = array(); $Controller->constructClasses(); $Controller->ControllerPost->virtualFields = array( diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 6d53b0996..1a6473ca4 100644 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -62,6 +62,32 @@ class ModelReadTest extends BaseModelTest { $result = $Post->field('two'); $this->assertEqual($result,2); + $result = $Post->find('first',array( + 'conditions' => array('two' => 2), + 'limit' => 1 + )); + $this->assertEqual($result['Post']['two'],2); + + $result = $Post->find('first',array( + 'conditions' => array('two <' => 3), + 'limit' => 1 + )); + $this->assertEqual($result['Post']['two'],2); + + $result = $Post->find('first',array( + 'conditions' => array('NOT' => array('two >' => 3)), + 'limit' => 1 + )); + $this->assertEqual($result['Post']['two'],2); + + $dbo =& $Post->getDataSource(); + $Post->virtualFields = array('other_field' => $dbo->name('Post.id') . ' + 1'); + $result = $Post->find('first',array( + 'conditions' => array('other_field' => 3), + 'limit' => 1 + )); + $this->assertEqual($result['Post']['id'],2); + ClassRegistry::flush(); $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'),'Model'); $Writing->virtualFields = array('two' => "1 + 1");