MS SQL guid problem with model relations

I have been using Yii for a while and find it very good. I have to currently use MS SQL for a client with an existing complex db. The connection works fine.

In creating models, if I do not set anything in the "relations" function everything works fine, but if I try to set a relationship like

on Profile Model

return array(

'Owner'=>array(self::HAS_ONE, 'User', 'UserID'),

);

where the table User has a PK of UserID which is a guid not an integer

then I get an error as follows

CDbException

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.

I have tried to find a way around this, but would like to try the lazy loading of AR.

Anyone have any ideas to make this work?

After a long time of having to use views to get around this, I finally saw documented that some tables need the primary key to be explicitly set.

So in the model folder for each Class I added a function as follows




        public function primaryKey()

	{

	    return 'UserId';

	    // For composite primary key, return an array like the following

	    // return array('pk1', 'pk2');

	}

and magically everything working as it should in Yii. very nice

Hope this helps someone like myself who got stuck.