Working on virtual fields on order clause.

This commit is contained in:
José Lorenzo Rodríguez 2009-11-12 08:42:41 -04:30
parent 0ab2078284
commit 2503632327
2 changed files with 19 additions and 1 deletions

View file

@ -1018,7 +1018,7 @@ class Model extends Overloadable {
function hasField($name, $checkVirtual = false) { function hasField($name, $checkVirtual = false) {
if (is_array($name)) { if (is_array($name)) {
foreach ($name as $n) { foreach ($name as $n) {
if ($this->hasField($n)) { if ($this->hasField($n,$checkVirtual)) {
return $n; return $n;
} }
} }

View file

@ -688,6 +688,24 @@ class ControllerTest extends CakeTestCase {
$this->assertFalse(isset($Controller->params['paging']['ControllerPost']['options'][0])); $this->assertFalse(isset($Controller->params['paging']['ControllerPost']['options'][0]));
} }
function testPaginateOrderVirtualField() {
$Controller =& new Controller();
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->ControllerPost->virtualFields = array('offset_test' => 'ControllerPost.id + 1');
$Controller->paginate = array(
'fields' => array('id', 'title'),
'order' => 'offset_test',
'limit' => 1
);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(2, 3));
}
/** /**
* testDefaultPaginateParams method * testDefaultPaginateParams method
* *