relational activerecords on mysql views - how to setup primary keys

I want to create relational activerecord on a mysql view.

You cannot set primarykeys on mysql view's, so the command


result in an error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘t1.’ in ‘on clause’

Source File


00306:            }


00308:            if($this->_connection->enableProfiling)

00309:                Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');


00311:            return $result;

00312:        }

00313:        catch(Exception $e)

00314:        {

00315:            if($this->_connection->enableProfiling)

00316:                Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');

00317:            Yii::log('Error in querying SQL: '.$this->getText().$params,CLogger::LEVEL_ERROR,'system.db.CDbCommand');

00318: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',

00319:                array('{error}'=>$e->getMessage())));

00320:        }

00321:    }

00322: }

everything is fine if i use a normal mysql table with primarykey…

How can I set a column as primary key in the activerecord childclass?

Best regards - Jens

It is not officially supported to use AR with views.

Having said that, you may try overriding primaryKey() method in your AR class.

thank's a lot … that is exactly what i need…