Answer the question
In order to leave comments, you need to log in
How to count the number of records in related tables, via ActiveRecord?
I have three tables.
table1->hasMany(table2)->hasMany(table3);
How it is possible to receive an amount of records in the third table if to make in the first selection under conditions.?
Answer the question
In order to leave comments, you need to log in
class User ....
public function getNapravlenie(){
return $this->hasMany(Napravlenie::className(),['historyID'=>'id']);
}
public function getAnaliz(){
return $this->hasMany(CheckAnaliz::className(), ['napravlenieID' => 'id'])->via('napravlenie');
}
public function getAnalizCount(){
return count($this->analiz);
}
....
$users = Users::find()->with(['analiz','napravlenie'])->all();
foreach($users as $one){
echo $one->id . " = " . $one->analizCount;
}
joinWith() && count()
Task context and code examples are needed, it's hard to tell anything without them
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question