Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

(Fixes issue 716)

  • Loading branch information...
commit 4b9f08678c2c179066b349f1d600f170d5386846 1 parent e8d3a3d
qiang.xue authored
Showing with 5 additions and 6 deletions.
  1. +1 −0  CHANGELOG
  2. +4 −6 framework/db/ar/CActiveFinder.php
View
1  CHANGELOG
@@ -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)
View
10 framework/db/ar/CActiveFinder.php
@@ -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');
@@ -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))
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.