Sorting a data provider by non-database attribute

I am still trying to get my head around how DataProviders work and I have run into a problem. I have a table in one database called users which contains basic contact information.

Some of those users are IT support personnel and are called CSR’s. In a second database I have a table called CSR which includes a user_id mapping back to the user table.

Because of limitations with Yii, I cannot create a direct relation between CSR and User since they are in different databases.

I want to create a page that lists all CSR’s in alphabetical order using a DataProvider. Normally I would do something like:




$dataProvider=new CActiveDataProvider('csr',array(

                                        'criteria'=>array(

                                            'with'=>array('user'),

                                            'order'=>"csr.name ASC"

                                   )));



But this obviously throws an error because there is no relationship user.

Does anyone have any ideas on how to do something like this?

You may be able to do this:




$dataProvider=new CActiveDataProvider('csr',array(

                                        'criteria'=>array(

                                            'join'=>'LEFT JOIN otherDB.dbo.user u ON u.id=user_id',

                                            'order'=>"csr.name ASC"

                                   )));



Haven’t tried it though.