Active relations

I'm having trouble using my active relations properly.

Here is an SQL statement that gets me what I want. 

SELECT * FROM person

  INNER JOIN name ON name.name_type='04'


(Well, this gets me some redundancy and extra fields, but I'll clean that up later.)

A person can have multiple names, one each of several name_types, the cannonical name having name_type '04'.  That's overkill for this app, but I'm implementing someone else's standard.

Now I want to modify yiic shell generated model and crud files so that (eg.) the person/show can display name.name_last for name.name_type '04'.  I've tried various things; below shows the current version.

In the Person model, Person::relations() returns an array item:

'name' => array(

    self::HAS_ONE, 'Name', 'person_id',

    'on' => "name_type='04'",

    'joinType' => 'INNER JOIN',


The relevant line in PersonController is:

$this->_person=Person::model()->findbyPk($id!==null ? $id : $_GET['id']);

The relevant line in person/shoe is:

<td><?php CHtml::encode($person->name->name_last); ?></td>

The app displays a blank last name even though the SELECT statement above gives me a name_last of 'Prufrock'.

I've tried variations of my code, but I can't seem to get it right.  I'm using yii-1.0.2.r614.

You forgot “echo”. ;)

YIKES.  I could swear I had it in there originally…  I’m a bit young to having such senior moments.  :-[