use andWhere() in AR::find() to work properly with default scope

fixes #1469
This commit is contained in:
Carsten Brandt
2013-12-12 12:07:28 +01:00
parent 3fba6dc314
commit 43f19e8aee
5 changed files with 33 additions and 4 deletions

View File

@@ -67,7 +67,7 @@ class ActiveRecord extends BaseActiveRecord
{
$query = static::createQuery();
if (is_array($q)) {
if (count($q) == 1 && (array_key_exists(ActiveRecord::PRIMARY_KEY_NAME, $q))) {
if (count($q) == 1 && (array_key_exists(ActiveRecord::PRIMARY_KEY_NAME, $q)) && $query->where === null) {
$pk = $q[ActiveRecord::PRIMARY_KEY_NAME];
if (is_array($pk)) {
return static::mget($pk);
@@ -75,7 +75,7 @@ class ActiveRecord extends BaseActiveRecord
return static::get($pk);
}
}
return $query->where($q)->one();
return $query->andWhere($q)->one();
} elseif ($q !== null) {
return static::get($q);
}