Answer the question
In order to leave comments, you need to log in
Why does the "count()" method show the wrong number of elements???
There are two models, for example "categories" and "products"
a one-to-many relationship hasMany (one category has many products)
And let's say I have only one category, and there are five products of this category
, in theory, design
Categories::find()->joinWith('products')->limit(1)->count();
Answer the question
In order to leave comments, you need to log in
$query->groupBy(['id']);
ps. Sometimes it is useful to pull out the generated code via createCommand()->rawSql, feed it to the database, and look at the result.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question