[limb-svn] r7127 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Tue Jul 22 15:55:03 MSD 2008
Author: serega
Date: 2008-07-22 15:55:02 +0400 (Tue, 22 Jul 2008)
New Revision: 7127
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7127
Modified:
3.x/trunk/limb/active_record/src/lmbARQuery.class.php
3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php
Log:
-- now it's possible to use "with_lazy_attributes" magic parameter with lmbARQuery (should work with eager join too).
Modified: 3.x/trunk/limb/active_record/src/lmbARQuery.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARQuery.class.php 2008-07-22 10:00:08 UTC (rev 7126)
+++ 3.x/trunk/limb/active_record/src/lmbARQuery.class.php 2008-07-22 11:55:02 UTC (rev 7127)
@@ -18,7 +18,7 @@
protected $attach_relations = array();
protected $sort_params = array();
- function __construct($base_class_name, $conn, $sql = '')
+ function __construct($base_class_name, $conn, $sql = '', $magic_params = array())
{
$this->base_class_name = $base_class_name;
$this->base_object = new $this->base_class_name(null, $conn);
@@ -27,7 +27,7 @@
{
parent :: __construct($conn);
$this->addTable($this->base_object->getTableName());
- $this->_addFieldsForObject($this->base_object);
+ $this->_addFieldsForObject($this->base_object, '', '', $magic_params);
}
else
{
@@ -59,9 +59,15 @@
return $this->eagerAttach($relation_name, $params);
}
- protected function _addFieldsForObject($object, $table_name = '', $prefix = '')
+ protected function _addFieldsForObject($object, $table_name = '', $prefix = '', $magic_params = array())
{
- $fields = $object->getDbTable()->getColumnsForSelect($table_name, $object->getLazyAttributes(), $prefix);
+ $lazy_attributes = array();
+ if(!isset($magic_params['with_lazy_attributes']))
+ $lazy_attributes = $object->getLazyAttributes();
+ elseif(is_array($magic_params['with_lazy_attributes']))
+ $lazy_attributes = $magic_params['with_lazy_attributes'];
+
+ $fields = $object->getDbTable()->getColumnsForSelect($table_name, $lazy_attributes, $prefix);
foreach($fields as $field => $alias)
$this->addField($field, $alias);
}
@@ -123,7 +129,7 @@
$class_name = $relation_info['class'];
$object = new $class_name(null, $this->_conn);
- $this->_addFieldsForObject($object, $prefix . $relation_name, $prefix . $relation_name . '__');
+ $this->_addFieldsForObject($object, $prefix . $relation_name, $prefix . $relation_name . '__', $params);
$relation_type = $base_object->getRelationType($relation_name);
switch($relation_type)
@@ -175,7 +181,7 @@
$conn = lmbToolkit :: instance()->getDefaultDbConnection();
$object = new $class_name;
- $query = new lmbARQuery($class_name, $conn, $sql);
+ $query = new lmbARQuery($class_name, $conn, $sql, $params);
if(isset($params['criteria']) && $params['criteria'])
$criteria = lmbSQLCriteria :: objectify($params['criteria']);
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php 2008-07-22 10:00:08 UTC (rev 7126)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARAttributesLazyLoadingTest.class.php 2008-07-22 11:55:02 UTC (rev 7127)
@@ -29,6 +29,19 @@
$this->_checkLazyness($object2, $annotation, $content);
}
+ function testForceToLoadLazyAttributes()
+ {
+ $object1 = $this->_createActiveRecord('Some annotation', 'Some content');
+ $object2 = $this->_createActiveRecord('Some other annotation', 'Some other content');
+
+ $query = lmbARQuery :: create('LazyTestOneTableObject', $params = array('with_lazy_attributes' => ''));
+ $arr = $query->fetch()->getArray();
+ $this->assertTrue(array_key_exists('annotation', $arr[0]->exportRaw()));
+ $this->assertTrue(array_key_exists('content', $arr[0]->exportRaw()));
+ $this->assertTrue(array_key_exists('annotation', $arr[1]->exportRaw()));
+ $this->assertTrue(array_key_exists('content', $arr[1]->exportRaw()));
+ }
+
function testLazyWorksOkForEagerJoin_OneToOneRelations()
{
$person = new PersonForLazyAttributesTest();
More information about the limb-svn
mailing list