[limb-svn] r6713 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Mon Jan 21 13:31:21 MSK 2008
Author: serega
Date: 2008-01-21 13:31:21 +0300 (Mon, 21 Jan 2008)
New Revision: 6713
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6713
Modified:
3.x/trunk/limb/active_record/src/lmbARQuery.class.php
3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php
3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php
Log:
-- now lmbARQuery "saves" all addOrder() calls until fetch() method is call. All sorting params are applied to fetched iterator.
Modified: 3.x/trunk/limb/active_record/src/lmbARQuery.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARQuery.class.php 2008-01-21 09:18:22 UTC (rev 6712)
+++ 3.x/trunk/limb/active_record/src/lmbARQuery.class.php 2008-01-21 10:31:21 UTC (rev 6713)
@@ -16,6 +16,7 @@
protected $_base_object;
protected $_join = array();
protected $_attach = array();
+ protected $_sort_params = array();
function __construct($base_class_name, $conn, $sql = '')
{
@@ -54,6 +55,16 @@
$this->addField($field, $alias);
}
+ function addOrder($field, $type='ASC')
+ {
+ if(is_array($field))
+ {
+ $this->_sort_params = $this->_sort_params + $field;
+ }
+ else
+ $this->_sort_params[$field] = $type;
+ }
+
function fetch($decorate = true)
{
$this->_applyJoins($this->_base_object, $this->_join);
@@ -65,7 +76,11 @@
$rs = $this->_decorateWithJoinDecorator($rs);
- return $this->_decorateWithAttachDecorator($rs);
+ $rs = $this->_decorateWithAttachDecorator($rs);
+
+ $rs->sort($this->_sort_params);
+
+ return $rs;
}
protected function _applyJoins($base_object, $joins, $parent_relation_name = '')
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php 2008-01-21 09:18:22 UTC (rev 6712)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARQueryTest.class.php 2008-01-21 10:31:21 UTC (rev 6713)
@@ -30,6 +30,22 @@
$this->assertIsA($arr[1], 'TestOneTableObject');
$this->assertEqual($arr[1]->getAnnotation(), $object2->getAnnotation());
}
+
+ function testSimpleFetch_WithSort()
+ {
+ $object1 = $this->creator->createOneTableObject(10);
+ $object2 = $this->creator->createOneTableObject(20);
+
+ $query = lmbARQuery :: create('TestOneTableObject', array('sort' => array('ordr' => 'DESC')), $this->conn);
+ $iterator = $query->fetch();
+ $iterator->sort(array('id' => 'ASC'));
+ $arr = $iterator->getArray();
+
+ $this->assertIsA($arr[0], 'TestOneTableObject');
+ $this->assertEqual($arr[0]->getAnnotation(), $object1->getAnnotation());
+ $this->assertIsA($arr[1], 'TestOneTableObject');
+ $this->assertEqual($arr[1]->getAnnotation(), $object2->getAnnotation());
+ }
function testFetch_Join_RelatedHasOneObject()
{
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php 2008-01-21 09:18:22 UTC (rev 6712)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARTestingObjectMother.class.php 2008-01-21 10:31:21 UTC (rev 6713)
@@ -117,19 +117,20 @@
class lmbARTestingObjectMother
{
- function initOneTableObject()
+ function initOneTableObject($ordr = '')
{
$object = new TestOneTableObject();
$object->set('annotation', 'Annotation ' . rand(0, 1000));
$object->set('content', 'Content ' . rand(0, 1000));
$object->set('news_date', date("Y-m-d", time()));
- $object->set('ordr', rand(0, 1000));
+ $ordr = $ordr ? $ordr : rand(0, 1000);
+ $object->set('ordr', $ordr);
return $object;
}
- function createOneTableObject()
+ function createOneTableObject($ordr = '')
{
- $object = $this->initOneTableObject();
+ $object = $this->initOneTableObject($ordr);
$object->save();
return $object;
}
More information about the limb-svn
mailing list