Model Class With Sql-Query As Datasource

Is it possible to define a CActiveRecord Model Class

and using a sql-query result as a datasource

instead of a table name ?

My goal is to create a model which would be based on a complex sql query

but it should be of CActiveRecord type in order to be used in GridViews

with correct sorting , filtering etc.

I already tried to use a CSqlDataProvider as a datasource for my Gridview

but although the grid gets filled properly I can’t have the ability of filtering.

Also the solution provided here

forces me to use additional Model classes for all tables involved in my complex sql-query and bind them with the basic model class via relations.

I’m desperate :(

Can you create a view in your database instead?