Yii Framework Forum: How To Build Relations To Display Columns Of 4 Tables In Cgridview Of Admin.php - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Build Relations To Display Columns Of 4 Tables In Cgridview Of Admin.php Rate Topic: -----

#1 User is offline   Rudra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 118
  • Joined: 12-July 13

Posted 26 July 2013 - 12:44 AM

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.
0

#2 User is offline   Rudra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 118
  • Joined: 12-July 13

Posted 26 July 2013 - 01:11 AM

Can anyone suggest me
0

#3 User is offline   Rudra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 118
  • Joined: 12-July 13

Posted 26 July 2013 - 02:10 AM

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
0

#4 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 26 July 2013 - 02:29 AM

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
CodeSutra
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users