diff --git a/generator/lib/behavior/aggregate_column/AggregateColumnRelationBehavior.php b/generator/lib/behavior/aggregate_column/AggregateColumnRelationBehavior.php
index <HASH>..<HASH> 100644
--- a/generator/lib/behavior/aggregate_column/AggregateColumnRelationBehavior.php
+++ b/generator/lib/behavior/aggregate_column/AggregateColumnRelationBehavior.php
@@ -116,12 +116,14 @@ class AggregateColumnRelationBehavior extends Behavior
 	protected function addQueryFindRelated($builder)
 	{
 		$foreignKey = $this->getForeignKey();
+		$foreignQueryBuilder = $builder->getNewStubQueryBuilder($foreignKey->getForeignTable());
+		$builder->declareClass($foreignQueryBuilder->getFullyQualifiedClassname());
 		$relationName = $this->getRelationName($builder);
 		return $this->renderTemplate('queryFindRelated', array(
 			'foreignTable'     => $this->getForeignTable(),
 			'relationName'     => $relationName,
 			'variableName'     => self::lcfirst($relationName),
-			'foreignQueryName' => $foreignKey->getForeignTable()->getPhpName() . 'Query',
+			'foreignQueryName' => $foreignQueryBuilder->getClassname(),
 			'refRelationName'  => $builder->getRefFKPhpNameAffix($foreignKey),
 		));
 	}
[aggregate] Fix behavior when used with namespaces.

Closes #<I>.