Wiki: CActiveRelation HAS_MANY BELONGS_TO based on secondary key
In the Model class, I overrode the getTableSchema and manually defined the foreign keys like so:
And in the corresponding table:
Now the standard relation definitions work directly!
as well as
public function getTableSchema()
{
$table = parent::getTableSchema();
$table->columns['sid']->isForeignKey = true;
$table->foreignKeys['sid'] = array('Click', 'm_sid');
return $table;
}
And in the corresponding table:
public function getTableSchema()
{
$table = parent::getTableSchema();
$table->columns['m_sid']->isForeignKey = true;
$table->foreignKeys['m_sid'] = array('Message', 'sid');
return $table;
}
Now the standard relation definitions work directly!
'clicks'=>array( self::HAS_MANY, 'Click', 'm_sid' ),
as well as
'message'=>array( self::BELONGS_TO, 'Message', 'sid'),
Leave a Comment