Model scopes get processed by Yii even when you don't use the scope?!

So I ran into an interesting problem. I’m using scopes to return data that only belongs to a user, base on his account ID.

	public function scopes() {

		return array(









I have 2 different apps accessing the model. One of the apps has no idea about users, logins, etc…its just pulling data. The other app is the front end, which needs to only show the user their own data.

However the problem comes in that the USER scope causes the first app to error, but it isn’t even being used. Is this the way it should work? My guess is the failure is because Yii::app()->user doesn’t exist in the first app, but always exists in the second.

Still, I’m puzzled as to why Yii would even look at the scope if it isn’t being used.





I found this in my searching:

Seems to be a reasonable answer, I’m going to try to implement and see what happens!



probably in your case usage of behavior is unneeded overhead, you can achieve the same result just using method-based named scope inside you AR model class.