Set the JOIN clause of the relation

Hello everyone!

I need help.

I have an access log table that stores the user login, date and IP access.

To keep the history even after the user deleted, the log table has no foreign key in the users table. However, they "connect" through the login field, since it does not help much to use the id as history. If a user is deleted, lost the complete data, but I have to login to identify it.

Follows the model:

My problem is to create the relation.

How can I indicate to the Yii which fields will be used in the join clause? I can not simply use the attribute ‘join’, since it is used to include another clause and does not change the main clause.


I believe that is not the best solution, but I managed to solve my problem.

The main issue is the order of fields to create the primary key in the log table.

"Magically," the relation work after I placed the "login" in the first position of the key:

public function relations() {

    return array(

        'idUser' => array(self::HAS_ONE, 'User', 'login',),