Skip to content

Commit

Permalink
(Fixes issue 716)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.xue committed Jun 25, 2010
1 parent e8d3a3d commit 4b9f086
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -30,6 +30,7 @@ Version 1.1.3 to be released
- Bug: Fixed AR memory leaks on PHP<5.3 (Sam Dark, parpaing)
- Enh #217: Added support to allow using related objects as selection values in CHtml (Qiang)
- Enh #663: Improved CSecurityManager to allow customizing the crypt/hash algorithms being used (Qiang)
- Enh #716: Improved the performance of statistical query in AR (Qiang)
- Enh #862: Enhanced CSort virtual attributes and support for related tables (Qiang)
- Enh #887: Relative URL's will be returned when using a parameterized hostname url rule that has the current hostinfo (Qiang)
- Enh #930: Updated CStarRating's jQuery plugin to v3.13, updated jQuery Metadata plugin (Sam Dark)
Expand Down
10 changes: 4 additions & 6 deletions framework/db/ar/CActiveFinder.php
Expand Up @@ -1358,9 +1358,9 @@ private function queryOneMany()

$records=$this->_parent->records;

$where=empty($relation->condition)?'' : ' WHERE ('.$relation->condition.')';
$where=empty($relation->condition)?' WHERE ' : ' WHERE ('.$relation->condition.') AND ';
$group=empty($relation->group)?'' : ', '.$relation->group;
$having=empty($relation->having)?'' : ' AND ('.$relation->having.')';
$having=empty($relation->having)?'' : ' HAVING ('.$relation->having.')';
$order=empty($relation->order)?'' : ' ORDER BY '.$relation->order;

$c=$schema->quoteColumnName('c');
Expand All @@ -1371,9 +1371,8 @@ private function queryOneMany()
{
$col=$table->columns[$fks[0]]->rawName;
$sql="SELECT $col AS $c, {$relation->select} AS $s FROM {$table->rawName}"
.$where
.$where.'('.$builder->createInCondition($table,$fks[0],array_keys($records)).')'
." GROUP BY $col".$group
." HAVING ".$builder->createInCondition($table,$fks[0],array_keys($records))
.$having.$order;
$command=$builder->getDbConnection()->createCommand($sql);
if(is_array($relation->params))
Expand All @@ -1399,9 +1398,8 @@ private function queryOneMany()
$cols[$name]=$name.' AS '.$schema->quoteColumnName('c'.$n);
}
$sql='SELECT '.implode(', ',$cols).", {$relation->select} AS $s FROM {$table->rawName}"
.$where
.$where.'('.$builder->createInCondition($table,$fks,$keys).')'
.' GROUP BY '.implode(', ',array_keys($cols)).$group
.' HAVING '.$builder->createInCondition($table,$fks,$keys)
.$having.$order;
$command=$builder->getDbConnection()->createCommand($sql);
if(is_array($relation->params))
Expand Down

0 comments on commit 4b9f086

Please sign in to comment.