Data Provider and named scopes

I have just switched to using CActiveDataProvider descendant in my application and there is one thing that is inconvenient, that is using named scopes. There is no way to easily reuse scopes when specifying what data should be returned. My solution was to introduce a callback event that would be called instead of last part of fetchData and where I could use named scopes, but perhaps there is some better way I am missing? Would appreciate your suggestions.

Thank you,

Oleh Khoma

yeah I am trying to figure out a solution for this as well. I was originally using a defaultScope, but that got messy with lazyLoading relational calls so I switched to a named scope, but now I can’t figure out a good way to use it with the CActiveDataProvider…

Have you tried looking at this extension?


Named scopes can be re-used in CActiveDataProvider.

i.e. new CActiveDataProvider(ClassName::model()->scopeName());

Remember: adding the findAll() method breaks it! Because findAll() actually outputs an array of models, in which case should be handled by the CArrayDataProvider().