public final function MapParentKeysToRelatedRow(array $ParentRows, array $RelatedRows)
{
if (count($RelatedRows) === 0) {
return [];
}
if (count($ParentRows) === 1) {
return [key($ParentRows) => reset($RelatedRows)];
} else {
$MappedRelatedRows = [];
$ForeignKey = $this->GetForeignKey();
if ($this->IsInversed()) {
$ParentRowColumns = $ForeignKey->GetReferencedColumns();
$RelatedRowColumns = $ForeignKey->GetParentColumns();
} else {
$ParentRowColumns = $ForeignKey->GetParentColumns();
$RelatedRowColumns = $ForeignKey->GetReferencedColumns();
}
$HashedParentRowToKeyMap = $this->MakeHashedDataToKeyMap($ParentRows, $ParentRowColumns);
$KeyedRelatedRows = $this->IndexRowsByHashedColumnValues($RelatedRows, $RelatedRowColumns);
foreach ($HashedParentRowToKeyMap as $HashedData => $ParentKey) {
$MappedRelatedRows[$ParentKey] = isset($KeyedRelatedRows[$HashedData]) ? $KeyedRelatedRows[$HashedData] : null;
}
return $MappedRelatedRows;
}
}