shanhsu
(Shanhsu)
1
In my DB, there are two tables User and Post. Relation between User and Post is HAS_MANY. Post BELONGS_TO User.
I would like to show all users and belonging posts in CGridView. However, I can’t get relational data. Only User data.
What I want should be like this
User Id Post Id Post Data
1 1 Test
1 2 Test2
2 3 Test
Model user
‘post’ => array(self::HAS_MANY, ‘Post’, ‘user_id’)
Model post
‘user’ => array(self::BELONG_TO, ‘User’, ‘user_id’)
Thanks for your help
Hi,
Make sure you have to retrieve data from both tables using a relation.
So as of now you have made relation in models.
Use the following example code before passing data to any of data providers
$dataX = User::model()->with('author','categories')->findAll(); //Customize according to your relationship
//Now give the $dataX to your dataprovider
Hope it will work!
Cheers!