on relationships

hi all

   i tried to display name instead of id in my gridview and listview by using relationships in model.

i tried the below code and it worked fine.


		return array('block' => array(self::BELONGS_TO, 'Block', 'rev_block_name')



and in my gridview


array(            // display 'create_time' using an expression

            'name'=>'rev_block_name',

            'value'=>'$data->block->block_name',

        ),

this worked fine for me.

now if i need block_name in another model class i am getting an error "unknown column".i clearly defined my relationship but i am not able to figure out what is wrong with it.

one question: can we use name that is to be displayed in multiple relations.

What’s the table “block” structure?

i dont want to define a relation in database.

As far as I know, this line:




 $data->block->block_name



will try to access loaded database data attributes either from current model or related models.

So the line above is trying to access attribute that will never exist, I guess.

Instead try:




  'value'=>'Block::model()->block_name',



(block_name should be public property)

Lubos