Hi,
I have found many threads on this, mostly from 2010, few from 2011:
http://www.yiiframework.com/search/?q=resetscope&lang=&type=
But it seems that nobody has solved the problem: if you have a defaultScope in a model class which is used in a relation, but in that relation you don’t want to use it, there’s no way to reset it. For instance, assume that you normally want to see only active posts in a blog, so you define inside the Posts class this defaultScope:
public function defaultScope()
{
$alias = $this->getTableAlias(false, false);
return array(
'condition'=>$alias.".active='1'"
);
}
but then you need to see every post, active AND inactive, writen by a given user, and you establish a relation in User class:
public function relations()
{
return array(
'allposts'=>array(self::BELONGS_TO, 'Posts', 'userId'),
);
}
then if you use:
$criteria->with = array(
‘allposts’=>array(‘scopes’=>array(‘resetScope’)),
);
but this won’t reset the default scope. And this won’t work either:
public function relations()
{
return array(
'allposts'=>array(self::BELONGS_TO, 'Posts', 'userId', 'scopes'=>array('resetScope')),
);
}
So, this problem is a real pain in the a$$ (sorry, too many hours trying to figure out how to ignore the default scope ). Using no defaultScopes is not an option, at least for me at this point, because it implies modifying a ton of criterias which assume the defaultScope exist. So, what can be done? Any help will be appreciated.
Regards.