Permalink
Browse files

(Fixes issue 1001) Added CActiveRecord::resetScope() that resets all …

…scopes and criterias applied including default scope.
  • Loading branch information...
1 parent 1fc3c55 commit b19a62a56db2adc4289a180c46b7014ef53d23a7 alexander.makarow committed Apr 20, 2010
Showing with 20 additions and 0 deletions.
  1. +1 −0 CHANGELOG
  2. +14 −0 framework/db/ar/CActiveRecord.php
  3. +5 −0 tests/unit/framework/db/ar/CActiveRecordTest.php
View
@@ -87,6 +87,7 @@ Version 1.1.1 March 14, 2010
- Enh #955: Added validateValue() to CUrlValidator and CEmailValidator (Qiang)
- Enh #971: Added CDbCriteria::addNotInCondition() (Sam Dark)
- Enh #992: Added 'data' option to CTabView.tabs property (Qiang)
+- Enh #1001: Added CActiveRecord::resetScope() that resets all scopes and criterias applied including default scope (Sam Dark)
- Enh #1093: CJSON now tries to use native PHP functions prior to use Yii implementation (Sam Dark)
- Enh: Refactored the blog demo to make use of the new CActiveForm and the filtering feature of CGridView (Qiang)
- Enh: Improved the code generated by yiic, including menu refactoring, filtering/search support, and using active form (Qiang)
@@ -303,6 +303,20 @@ public function defaultScope()
}
/**
+ * Resets all scopes and criterias applied including default scope.
+ *
+ * @return CActiveRecord
+ * @since 1.1.2
+ */
+ public function resetScope()
+ {
+ if($this->_c!==null)
+ $this->_c=new CDbCriteria();
+
+ return $this;
+ }
+
+ /**
* Returns the static model of the specified AR class.
* The model returned is a static instance of the AR class.
* It is provided for invoking class-level methods (something similar to static class methods.)
@@ -750,6 +750,11 @@ public function testScopes()
$this->assertEquals(2,$posts[1]->id);
}
+ public function testResetScope(){
+ $posts=Post::model()->post23()->resetScope()->findAll();
+ $this->assertEquals(5,count($posts));
+ }
+
public function testLazyLoadingWithConditions()
{
$user=User::model()->findByPk(2);

0 comments on commit b19a62a

Please sign in to comment.