public function createCommand($criteria, $foreignKeys, $indexValues, $sourceKeys)
{
$innerJoin = $this->getAssociationJoin($foreignKeys, $indexValues, $sourceKeys);
$fkTable = $this->getForeignTable()->getTableFullName();
$srcColumns = $this->getSourceColumns($sourceKeys);
if (($where = $criteria->getCondition()) === null) {
$where = '1=1';
}
$sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}";
$parameters = $criteria->getParameters()->toArray();
$ordering = $criteria->getOrdersBy();
$limit = $criteria->getLimit();
$offset = $criteria->getOffset();
$builder = $this->getForeignCommandBuilder()->getBuilder();
$command = $builder->applyCriterias($sql, $parameters, $ordering, $limit, $offset);
$this->getCommandBuilder()->onCreateCommand($command, $criteria);
return $command;
}