Skip to content

Commit

Permalink
yii\db\ActiveQuery::removeDuplicatedModels() throws exception if mo…
Browse files Browse the repository at this point in the history
…del primary key is empty
  • Loading branch information
klimov-paul committed May 19, 2015
1 parent 0d8fadc commit 68351e7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions framework/db/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace yii\db;

use yii\base\InvalidConfigException;

/**
* ActiveQuery represents a DB query associated with an Active Record class.
*
Expand Down Expand Up @@ -235,6 +237,7 @@ public function populate($rows)
* Removes duplicated models by checking their primary key values.
* This method is mainly called when a join query is performed, which may cause duplicated rows being returned.
* @param array $models the models to be checked
* @throws InvalidConfigException if model primary key is empty
* @return array the distinctive models
*/
private function removeDuplicatedModels($models)
Expand All @@ -257,6 +260,8 @@ private function removeDuplicatedModels($models)
$hash[$key] = true;
}
}
} elseif (empty($pks)) {
throw new InvalidConfigException("Primary key of '{$class}' can not be empty.");
} else {
$pk = reset($pks);
foreach ($models as $i => $model) {
Expand Down

0 comments on commit 68351e7

Please sign in to comment.