How To Build Relations To Display Columns Of 4 Tables In Cgridview Of Admin.php

I’m a newbie. Now I have a requirement where I need to build the relations between more than 3 tables.

I have 4 tables namely, Message, Flat, Person, Mapping tables.

Now, below tables have the following fields:

Message:

Id int(11) NOT NULL AUTO_INCREMENT,

Mapid int(11) DEFAULT NULL,

PRIMARY KEY (Id),

KEY FK41715B218022FC0 (MapId)

Mapping

Id int(11) NOT NULL AUTO_INCREMENT,

FlatId int(11) DEFAULT NULL,

PRIMARY KEY (Id),

KEY FKE2B3C68A24F94F50 (FlatId),

Flat

Id int(11) NOT NULL AUTO_INCREMENT,

PersonId int(11) DEFAULT NULL,

PRIMARY KEY (Id),

KEY FK2FFF79122B94A6 (PersonId),

Person

Id int(11) NOT NULL AUTO_INCREMENT,

Name varchar(255) DEFAULT NULL,

FlatId int(11) DEFAULT NULL,

Phone varchar(255) DEFAULT NULL,

PRIMARY KEY (Id),

KEY FKC4E39B55AF5432C (FlatId),

Now, I have to build relations in such a way that in the Cgridview(admin.php) of Message, i should display PersonId of flat table and Name and Phone of Person table along with the columns of Message table.

Can anyone suggest me

Defined relations like this

public function relations()

    {


            // NOTE: you may need to adjust the relation name and the related


            // class name for the relations automatically generated below.


            return array(                   


               'userflat' => array(self::BELONGS_TO, 'Mapping', 'PostedByUserFlatId'),


               'flat'=>array(self::HAS_ONE,'Flat',array('FlatId'=>'Id'),'through'=>'userflat'),


               'person'=>array(self::HAS_ONE,'Person',array('PersonId'=>'Id'),'through'=>'flat'),


            );





    }

How can I get values in Cgridview

Ok,

So, you want to display values from different model class in same Cgrid View Right.

So, if you have defined proper relations in your parent model class then you can easily get values for your related tables.

You should refer this link

Link 1

Link 2