Hello,
Let’s say i have 2 table: Author and Post.
class Author extends \yii\db\ActiveRecord {
public function getPosts() {
return $this->hasMany(Post::className(), ['author_id' => 'id']);
}
class Post extends \yii\db\ActiveRecord {
public function getAuthor() {
return $this->hasOne(Author::className(), ['id' => 'author_id']);
}
I want to display GridView tables with Authors and add 1 more column with total number of posts of each author. How to do it? What should i add to dataProviders. This column should be sortable and filter also should work there. I know how to do same with hasOne relation, but not with count hasMany.