Relational Black Magic Required

Hi,

I’m about to put a pencil up each nostril, and head-butt the desk. :-X

Im using Yii User and SRBAC modules

I need to be able to echo the first and last name of a user instead of the ID, the data is held in 2 tables.

Table : profiles (user_id,lastname,firstname,birthday)

Table : leads (id,create_time,update_time,id_lead,id_user,…client_1_title)

If a View shows id_user, I want it to actually show lastname firstname (or even username from the users table will do)

i’ve managed to get the update form to show the lastname and insert the id_user via :

<?php echo $form->dropDownList($model,‘id_user’, CHtml::listData(Profiles::model()->with(‘leads_rel’)->findAll(array(‘order’=>‘t.lastname ASC’)), ‘user_id’, ‘lastname’), array(‘empty’=>‘Please Select’)); ?>

I’m trying to do everything the Yii way, rather than plaster natve PHP code all over to achieve me goals…

Ok,

i think i’ve done it.

Model:


public function relations()

    {

        return array(

            'profile_rel'=>array(self::BELONGS_TO, 'Profiles', 'id_user'),

        );

    }

view.php


'attributes'=>array(

    'id',

    'create_time',

    'update_time',

    'id_lead',

    'client_1_title',

    .

    .

    .

    'profile_rel.lastname',

:D