I have defined a function getClicksCount() in my School model and a function actionActive() in my SchoolController and I want to use a ActiveDataProvider to show the results in a grid having the property clicksCount equal zero. Is that even possible?
public function getClicksCount()
{
return $this->hasMany(Click::class, ['school_id' => 'id'])->count();
}
How to change the actionActive() to fit my requirements?
// in School class:
// let it be regular relation
public function getClicks()
{
return $this->hasMany(Click::class, ['school_id' => 'id']);
}
[...]
// In SchoolSearch or wherever you need
School::find()
->joinWith("clicks")
->groupBy("id") // School primary key
->having("count(click.id) = :count", ["count" => 0]); // Click primary key
Bart I have another question; how to upgrade (add another having condition) to show all those schools who have all attributes âfirst_loginâ (in clicks table) set to NULL ?
I tried hit no success.
$dataProvider->query->joinWith('clicks')->groupBy('id')->having("count(click.id) = :count", ["count" => 0])->andHaving('count(code.first_login) IS NULL');