Accessing Data From Related Table

I have something like this:

I’m trying to get the data from table1_id from /protected/views/table3/(actions here)

These are my relations:


'table2' => array(self::HAS_MANY, 'Table2', 'table1_id'),


'table1' => array(self::BELONGS_TO, 'Table1', 'table1_id'),

'table3' => array(self::HAS_MANY, 'Table3', 'table2_id'),


'table2' => array(self::BELONGS_TO, 'Table2', 'table2_id'),

I just want to print it on any of my views.

I tried:

echo $data->table2->table1_id;

echo $model->table2->table1_id;

If I use var_dump it returns me null. What am I doing wrong?

Try this (assuming $model is a table3): $model->table2->table1->id