diff options
Diffstat (limited to 'framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php')
-rw-r--r-- | framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php index a86fdffd..bb2cc583 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php @@ -1,4 +1,4 @@ -<?php +<?php
/**
* Loads base active record relations class.
@@ -75,18 +75,28 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation $finder = $this->getContext()->getForeignRecordFinder();
$command = $this->createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys);
$srcProps = array_keys($sourceKeys);
- $type = get_class($finder);
$collections=array();
foreach($command->query() as $row)
{
$hash = $this->getObjectHash($row, $srcProps);
foreach($srcProps as $column)
unset($row[$column]);
- $collections[$hash][] = $finder->populateObject($type,$row);
+ $collections[$hash][] = $this->populateObject($finder, $row);
}
$this->setResultCollection($results, $collections, array_values($sourceKeys));
}
+
+ protected function populateObject($finder, $data)
+ {
+ $registry = $finder->getRecordManager()->getObjectStateRegistry();
+ if(!is_null($obj = $registry->getCachedInstance($data, false)))
+ return $obj;
+ $gateway = $finder->getRecordManager()->getRecordGateway();
+ $type = get_class($finder);
+ $obj = new $type($data);
+ return $registry->addCachedInstance($data,$obj);
+ }
/**
* @param TSqlCriteria
@@ -145,5 +155,5 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return "INNER JOIN {$refTable} ON ({$joinCondition}) AND {$index}";
}
-} +}
?>
\ No newline at end of file |