Answer the question
In order to leave comments, you need to log in
Yii2. How to count the number of records received?
There are 2 related tables, products and product_models. The first has 3 records, the second has 4.
The result of the code below, for some reason, is the number of records from the product_models table, i.e. - 4.
And I need count() to read only the quantity from the products table - 3 records.
1. $cat = [1, 2, 3, 15];
2. $query = Products::find()->select('*');
3. $query->innerJoinWith(['productModels']);
4. if ($cat) $query->where(['in', 'product_models.category_id', $cat]);
5. return $query->count();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question