summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei <>2008-02-04 11:09:46 +0000
committerwei <>2008-02-04 11:09:46 +0000
commit515beaea9b54627f33f58debfc8619be085f8d81 (patch)
treea2716706d9a4a6f9f6ff02814cfb7adabd0bccaf
parentf423f552e01310ae0338d1c4e413c1dc75ea10d5 (diff)
Fix ActiveRecord: multiple FK referencing same table causes incorrect retrieval.
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php11
1 files changed, 7 insertions, 4 deletions
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
index 4c238801..300dc26c 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
@@ -113,16 +113,19 @@ abstract class TActiveRecordRelation
$tableInfo=$from;
if($from instanceof TActiveRecord)
$tableInfo = $gateway->getRecordTableInfo($from);
+ //find first non-empty FK
foreach($tableInfo->getForeignKeys() as $fkeys)
{
if(strtolower($fkeys['table'])===strtolower($matchingTableName))
{
- if(!$loose && $this->getContext()->hasFkField())
- return $this->getFkFields($fkeys['keys']);
- else
- return $fkeys['keys'];
+ $hasFkField = !$loose && $this->getContext()->hasFkField();
+ $key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys'];
+ if(!empty($key))
+ return $key;
}
}
+
+ //none found
$matching = $gateway->getRecordTableInfo($matchesRecord)->getTableFullName();
throw new TActiveRecordException('ar_relations_missing_fk',
$tableInfo->getTableFullName(), $matching);